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

Unable to publish AOT compiled net9.0-ios apps #3808

Closed
jamescrosswell opened this issue Dec 2, 2024 · 4 comments · Fixed by #3841
Closed

Unable to publish AOT compiled net9.0-ios apps #3808

jamescrosswell opened this issue Dec 2, 2024 · 4 comments · Fixed by #3841
Labels
AOT Bug Something isn't working Platform: iOS
Milestone

Comments

@jamescrosswell
Copy link
Collaborator

When trying to publish the Sentry.Samples.Maui app to a physical device:

dotnet publish /t:Run -f net9.0-ios18.0 /p:_DeviceName=<Device_ID>

AOT compilation fails with a cryptic error. Adding the following properties gives us a bit more detail:

  <PropertyGroup>
    <SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
    <TrimmerSingleWarn>false</TrimmerSingleWarn>
  </PropertyGroup>

The error is then:

  Sentry.Samples.Maui net9.0-ios18.0 failed with 2 error(s) (30.1s) → bin/Release/net9.0-ios18.0/ios-arm64/Sentry.Samples.Maui.dll
    /_/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverterFactory.cs(33): AOT analysis error IL3050: System.Text.Json.Serialization.Converters.EnumConverterFactory.CreateConverter(Type,JsonSerializerOptions): Using member 'System.Text.Json.Serialization.Converters.EnumConverterFactory.Create(Type,EnumConverterOptions,JsonNamingPolicy,JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.
    /Users/jamescrosswell/.nuget/packages/microsoft.dotnet.ilcompiler/9.0.0/build/Microsoft.NETCore.Native.targets(317,5): error MSB3073: The command ""/Users/jamescrosswell/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/9.0.0/tools/ilc" @"obj/Release/net9.0-ios18.0/ios-arm64/native/Sentry.Samples.Maui.ilc.rsp"" exited with code -1.

It's still somewhat cryptic as we don't use the EnumConverterFactory anywhere directly, that I can tell.

Needs investigation.

@bricefriha
Copy link
Contributor

It's still somewhat cryptic as we don't use the EnumConverterFactory anywhere directly, that I can tell.

While we don't call it directly in the code, it looks like we do when we compile. 🤔

A similar issue was reported there dotnet/runtime#109177
and solved with this PR: dotnet/runtime#109180

Then, the fix was released as part of .net9.0.
That's the weirdest part. Since this error only popped up after the .net 9 update

@jamescrosswell
Copy link
Collaborator Author

Then, the fix was released as part of .net9.0.

Ah, there's actually a comment about a regression in net9.0:

Might need to add a sample app, as the analyzers won't help here.

@jamescrosswell
Copy link
Collaborator Author

This appears to be a problem with the Sentry.Samples.Maui project. I can publish test/Sentry.MauiTrimTest/Sentry.MauiTrimTest.csproj from the trim-warnings branch without any difficulty by running:

dotnet publish /t:Run test/Sentry.MauiTrimTest/Sentry.MauiTrimTest.csproj -c Release -f net9.0-ios18.0 /p:_DeviceName=00008030-00120D190A38802E

However the almost identical command to publish the sample app fails with error IL3053: Assembly 'System.Text.Json' produced AOT analysis warnings.

Need to try recreating the sample app from scratch using the new net9.0 template.

@jamescrosswell
Copy link
Collaborator Author

The reason we were getting analysis errors in Sentry.Samples.Maui.csproj but not in Sentry.MauiTrimTest.csproj is because we had set <PublishAot>true</PublishAot> in Sentry.Samples.Maui.csproj... which runs additional AOT analyzers.

I've added <PublishAot>true</PublishAot> to the trim test apps as well but, for the time being, have had to disable this when targeting iOS due to a bug/regression in System.Text.Json:

That bug is the root cause of the problems we're having publishing our sample app (and our trim test app) and being able to test anything in release apps.

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 Platform: iOS
Projects
Status: Done
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants