getsentry / sentry-dotnet

Sentry SDK for .NET
https://docs.sentry.io/platforms/dotnet
MIT License
606 stars 206 forks source link

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

Open jamescrosswell opened 2 days ago

jamescrosswell commented 2 days ago

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 commented 1 day ago

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 https://github.com/dotnet/runtime/issues/109177 and solved with this PR: https://github.com/dotnet/runtime/pull/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 commented 16 hours ago

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.