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

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

Open
jamescrosswell opened this issue Nov 25, 2024 · 0 comments · May be fixed by #3797
Assignees
Labels
AOT Bug Something isn't working
Milestone

Comments

@jamescrosswell
Copy link
Collaborator

jamescrosswell commented Nov 25, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AOT Bug Something isn't working
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

2 participants