akgulebubekir / Maui.DataGrid

DataGrid component for Maui
MIT License
261 stars 54 forks source link

Crashes in .NET 9 #200

Closed daltzctr closed 2 months ago

daltzctr commented 2 months ago

Describe the bug Application crashes on all platforms.

To Reproduce Steps to reproduce the behavior:

  1. Create a new .NET 9 RC1 MAUI project
  2. Add the Maui.DataGrid nuget
  3. Initialize it in some XAML.

Expected behavior To not crash the application

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Stack Trace

[0:] [13:46:57 FTL] Inner Exception: 
 System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Maui.Controls.Xaml.BindingExtension.<Microsoft.Maui.Controls.Xaml.IMarkupExtension<Microsoft.Maui.Controls.BindingBase>.ProvideValue>g__CreateBinding|40_0(<>c__DisplayClass40_0& ) in /_/src/Controls/src/Xaml/MarkupExtensions/BindingExtension.cs:line 46
   at Microsoft.Maui.Controls.Xaml.BindingExtension.Microsoft.Maui.Controls.Xaml.IMarkupExtension<Microsoft.Maui.Controls.BindingBase>.ProvideValue(IServiceProvider serviceProvider) in /_/src/Controls/src/Xaml/MarkupExtensions/BindingExtension.cs:line 27
   at Maui.DataGrid.DataGrid.InitializeComponent() in D:\Maui.DataGrid\Maui.DataGrid\Microsoft.Maui.Controls.SourceGen\Microsoft.Maui.Controls.SourceGen.CodeBehindGenerator\DataGrid.xaml.sg.cs:line 53
   at Maui.DataGrid.DataGrid..ctor() in D:\Maui.DataGrid\Maui.DataGrid\DataGrid.xaml.cs:line 46
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Constructor(Object obj, IntPtr* args)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

The issues are likely related to the mandatory compile time bindings in .NET 9. I see usages of x:DataType={x:Object} in the library, and this is no longer allowed in .NET 9. If this is the issue, a simple solution could be using reflection based bindings with x:DataType={x:Null}