Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET 9: Runtime crashes when utilizing legacy libraries. #24740

Closed
daltzctr opened this issue Sep 12, 2024 · 6 comments
Closed

.NET 9: Runtime crashes when utilizing legacy libraries. #24740

daltzctr opened this issue Sep 12, 2024 · 6 comments
Labels
area-xaml XAML, CSS, Triggers, Behaviors fixed-in-9.0.0-rc.2.24503.2 platform/android 🤖 platform/iOS 🍎 potential-regression This issue described a possible regression on a currently supported version., verification pending s/needs-attention Issue has more information and needs another look t/bug Something isn't working

Comments

@daltzctr
Copy link
Contributor

Description

MAUI class libraries that utilize the following features

  • Obsoleted controls such as Frame
  • Obsoleted APIs such as Device
  • Missing datatypes (previously this would fall back to reflection based bindings)
  • x:DataType={x:Object} which would previously fall back to reflection based bindings.

Will runtime crash when used in a consumer project. The consumer project has no warnings about any incompatibilities and will just crash.

Some examples of offending libraries are

Proposal:
I am not sure of the technical challenges on this, but it would be nice to either mark .NET 8 MAUI libraries with warnings as possibly incompatible, or detect incompatibilities in referenced libraries and throw a compile time error. This is no workaround and library maintainers must fix the issues by fixing the obsoleted references and ensure they are datatyping everything (replace x:DataType={x:Object} with x:DataType={x:Null} to explicitly opt in to reflection based bindings as a short term workaround.

Steps to Reproduce

  1. Create a new MAUI project
  2. Include the Maui.DataGrid (https://github.com/akgulebubekir/Maui.DataGrid) nuget
  3. Add a reference to datagrid in XAML, no need to add itemsource
  4. Build.
    • Observe no warnings at compile time
  5. Run the application. It will throw an exception that points to some Xaml activator and in Android, points to the datagrid library.

Link to public reproduction project repository

No response

Version with bug

9.0.0-rc.1.24453.9

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.82 SR8.2

Affected platforms

iOS, Android

Affected platform versions

No response

Did you find any workaround?

No. The only workaround has been to fix the references upstream.

Relevant log output

No response

@daltzctr daltzctr added the t/bug Something isn't working label Sep 12, 2024
Copy link
Contributor

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@jonathanpeppers
Copy link
Member

@daltzctr can you share the stack trace of some of these crashes?

Do we know if this change was in RC 1, it was merged only 2 weeks ago, so perhaps not:

The idea is it should restore a lot of previous behavior from .NET 8.

@jonathanpeppers
Copy link
Member

@daltzctr
Copy link
Contributor Author

@jonathanpeppers

Sharpnado (obsolete references, so not datatype related)

Unhandled managed exception: Exception has been thrown by the target of an invocation. (System.Reflection.TargetInvocationException)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
   at System.RuntimeType.CreateInstanceMono(Boolean nonPublic, Boolean wrapExceptions)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at Microsoft.Maui.Controls.Xaml.CreateValuesVisitor.Visit(ElementNode node, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.<>c__DisplayClass43_0.<SetTemplate>b__0()
   at Microsoft.Maui.Controls.ElementTemplate.CreateContent()
at Sharpnado.Tabs.TabHostView.CreateTabItem(Object item)
   at Sharpnado.Tabs.TabHostView.InitializeItems()
   at Sharpnado.Tabs.TabHostView.UpdateItemsSource()
   at Sharpnado.Tabs.TabHostView.OnPropertyChanged(String propertyName)
   at Microsoft.Maui.Controls.BindableObject.OnBindablePropertySet(BindableProperty property, Object original, Object value, Boolean didChange, Boolean willFirePropertyChanged)

Maui.DataGrid (x:Object and missing DataTypes)

[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)

@samhouts samhouts added platform/android 🤖 platform/iOS 🍎 potential-regression This issue described a possible regression on a currently supported version., verification pending labels Sep 12, 2024
@mattleibow mattleibow added s/needs-attention Issue has more information and needs another look area-xaml XAML, CSS, Triggers, Behaviors labels Sep 12, 2024
@mattleibow mattleibow added this to the .NET 9 Planning milestone Sep 12, 2024
jonathanpeppers added a commit to jonathanpeppers/maui that referenced this issue Sep 13, 2024
Fixes: dotnet#24740

Using this in a project:

    <PackageReference Include="akgul.Maui.DataGrid" Version="4.0.4" />

Then, in a XAML file:

    xmlns:dg="clr-namespace:Maui.DataGrid;assembly=Maui.DataGrid"
    ...
    <dg:DataGrid />

Would crash with:

    [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)

Inspecting the IL, I see:

    BindingBase val115 = ((IMarkupExtension<BindingBase>)(object)val31).ProvideValue((IServiceProvider)null);

So, it is indeed passed a `null` `IServiceProvider`.

Introduce a unit test and check for `null` as a fix.
@jonathanpeppers
Copy link
Member

@daltzctr this should hopefully fix Maui.DataGrid:

For Sharpnado.Tabs that could be a different issue, do you have a sample showing the problem?

github-actions bot pushed a commit to jonathanpeppers/maui that referenced this issue Sep 21, 2024
Fixes: dotnet#24740

Using this in a project:

    <PackageReference Include="akgul.Maui.DataGrid" Version="4.0.4" />

Then, in a XAML file:

    xmlns:dg="clr-namespace:Maui.DataGrid;assembly=Maui.DataGrid"
    ...
    <dg:DataGrid />

Would crash with:

    [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)

Inspecting the IL, I see:

    BindingBase val115 = ((IMarkupExtension<BindingBase>)(object)val31).ProvideValue((IServiceProvider)null);

So, it is indeed passed a `null` `IServiceProvider`.

Introduce a unit test and check for `null` as a fix.
rmarinho pushed a commit that referenced this issue Sep 23, 2024
Fixes: #24740

Using this in a project:

    <PackageReference Include="akgul.Maui.DataGrid" Version="4.0.4" />

Then, in a XAML file:

    xmlns:dg="clr-namespace:Maui.DataGrid;assembly=Maui.DataGrid"
    ...
    <dg:DataGrid />

Would crash with:

    [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)

Inspecting the IL, I see:

    BindingBase val115 = ((IMarkupExtension<BindingBase>)(object)val31).ProvideValue((IServiceProvider)null);

So, it is indeed passed a `null` `IServiceProvider`.

Introduce a unit test and check for `null` as a fix.
@jonathanpeppers
Copy link
Member

I believe this also would fix Sharpnado.Tabs, checking InitializeComponent() of BottomTabItem, I see the same issue:

image

But if @daltzctr has a sample, I could test for sure. Closing, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-xaml XAML, CSS, Triggers, Behaviors fixed-in-9.0.0-rc.2.24503.2 platform/android 🤖 platform/iOS 🍎 potential-regression This issue described a possible regression on a currently supported version., verification pending s/needs-attention Issue has more information and needs another look t/bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

4 participants