-
Notifications
You must be signed in to change notification settings - Fork 1.9k
NullReferenceException thrown at runtime when using OnPlatform with SourceGen enabled #34074
Description
Description
We’ve updated to SR4 and enabled SourceGen. The XAML compiled as expected with SourceGen enabled. However, a NullReferenceException is thrown at runtime. It appears to be caused by the OnPlatform XAML logic we have. When I add the following XAML:
<OnPlatform x:TypeArguments="View">
<On Platform="WinUI">
<Label Text="This is a label only visible on WinUI" />
</On>
</OnPlatform>the following exception is thrown:
System.NullReferenceException: Object reference not set to an instance of an object. at SourceGenRuntimeException.MainPage.InitializeComponent() in /Users/test/Desktop/SourceGenRuntimeException/obj/Generated/Microsoft.Maui.Controls.SourceGen/Microsoft.Maui.Controls.SourceGen.XamlGenerator/MainPage.xaml.xsg.cs:line 93
at SourceGenRuntimeException.MainPage..ctor() in /Users/test/Desktop/SourceGenRuntimeException/MainPage.xaml.cs:line 9
at SourceGenRuntimeException.App.CreateWindow(IActivationState activationState) in /Users/test/Desktop/SourceGenRuntimeException/App.xaml.cs:line 14
at Microsoft.Maui.Controls.Application.Microsoft.Maui.IApplication.CreateWindow(IActivationState activationState)
Steps to Reproduce
- Run the attached sample project.
- Compile the project and run it on a platform different from WinUI, as the OnPlatform example above targets WinUI. For instance, if the code is intended for Android, the issue will occur on all platforms except Android.
Link to public reproduction project repository
https://github.com/telerik/ms-samples/tree/main/Maui/SourceGenRuntimeException
Version with bug
10.0.40
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android, Windows, macOS
Affected platform versions
No response
Did you find any workaround?
No response