Skip to content

IL2026 from Microsoft.Maui.Controls.SourceGen when AOT compiling Sentry.Samples.Maui on net9.0-ios #3785

Description

@jamescrosswell

We're unable to compile the MAUI sample AOT:

  Sentry.Samples.Maui net9.0-ios failed with 4 error(s) (23.1s) → bin/Release/net9.0-ios/ios-arm64/Sentry.Samples.Maui.dll
    /code/sentry-dotnet/samples/Sentry.Samples.Maui/obj/Release/net9.0-ios/ios-arm64/Microsoft.Maui.Controls.SourceGen/Microsoft.Maui.Controls.SourceGen.CodeBehindGenerator/Resources_Styles_Styles.xaml.sg.cs(33): Trim analysis error IL2026: __XamlGeneratedCode__.__Type68A1B57D17E9473E.InitializeComponent(): Using member 'Microsoft.Maui.Controls.Xaml.OnPlatformExtension.Default.get' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The OnPlatformExtension is not trim safe. Use OnPlatform<T> instead.
    /code/sentry-dotnet/samples/Sentry.Samples.Maui/obj/Release/net9.0-ios/ios-arm64/Microsoft.Maui.Controls.SourceGen/Microsoft.Maui.Controls.SourceGen.CodeBehindGenerator/Resources_Styles_Styles.xaml.sg.cs(33): Trim analysis error IL2026: __XamlGeneratedCode__.__Type68A1B57D17E9473E.InitializeComponent(): Using member 'Microsoft.Maui.Controls.Xaml.OnPlatformExtension.Default.set' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The OnPlatformExtension is not trim safe. Use OnPlatform<T> instead.
    /code/sentry-dotnet/samples/Sentry.Samples.Maui/obj/Release/net9.0-ios/ios-arm64/linked/System.Text.Json.dll : error IL3053: Assembly 'System.Text.Json' produced AOT analysis warnings.

It's coming from the binding source generators, which is a bit odd, as the bindings in our Sentry.Samples.Maui project are blindingly simple.

Even more unusual, is that when looking at the generated source code referred to (e.g. Resources_Styles_Styles.xaml.sg.cs(33)) there is a pragma that is supposed to be explicitly ignoring this warning:

		[global::System.CodeDom.Compiler.GeneratedCode("Microsoft.Maui.Controls.SourceGen", "1.0.0.0")]
#if NET5_0_OR_GREATER
#endif
		private void InitializeComponent()
		{
#pragma warning disable IL2026, IL3050 // The body of InitializeComponent will be replaced by XamlC so LoadFromXaml will never be called in production builds
			global::Microsoft.Maui.Controls.Xaml.Extensions.LoadFromXaml(this, typeof(__Type68A1B57D17E9473E));
#pragma warning restore IL2026, IL3050
		}

I don't get the same in a brand new Maui app (although I haven't successfully AOT compiled one of those either - the process seems to run indefinitely... but at least it doesn't give any trim warnings).

There may be something we need to do to "upgrade" our sample from net8.0 to net9.0.

Originally posted by @jamescrosswell in #3729 (comment)

Solution from Tracking Issue

References

Metadata

Metadata

Labels

AOTBugSomething isn't working

Projects

Status
Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions