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

[Android AOT] Precompiling failing in .NET 9 #113672

Open
OvrBtn opened this issue Mar 18, 2025 · 9 comments
Open

[Android AOT] Precompiling failing in .NET 9 #113672

OvrBtn opened this issue Mar 18, 2025 · 9 comments

Comments

@OvrBtn
Copy link

OvrBtn commented Mar 18, 2025

Description

Hello, I have a .net 8 project and when I change it to .net 9 it works fine in debug but in release I get this:

C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\35.0.39\targets\Microsoft.Android.Sdk.Aot.targets(110,5): error : Precompiling failed for D:\a\StudentUsos\StudentUsos\StudentUsos\obj\Release\net9.0-android\android-x64\linked\StudentUsos.dll with exit code -1073740940. [D:\a\StudentUsos\StudentUsos\StudentUsos\StudentUsos.csproj::TargetFramework=net9.0-android]
C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\35.0.39\targets\Microsoft.Android.Sdk.Aot.targets(110,5): error :  [D:\a\StudentUsos\StudentUsos\StudentUsos\StudentUsos.csproj::TargetFramework=net9.0-android]

If I disable AOT it works fine but I wouldn't want to disable it completely.

I tried building other .net 9 project and it worked.
Also I got this error on github CI/CD so I guess it must be something with the code.

I have no idea how to make smaller reproduction project since the error doesn't point to anyting specific.

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

9.0.50 SR5 also tested and confirmed in 9.0.10

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.100 SR10

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

  StudentUsos -> D:\a\StudentUsos\StudentUsos\StudentUsos\bin\Release\net9.0-android\StudentUsos.dll
  Optimizing assemblies for size may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
  Optimizing assemblies for size. This process might take a while.
  Optimizing assemblies for size may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
  Optimizing assemblies for size. This process might take a while.
  [StudentUsos.dll] Exec (with response file contents expanded) in D:\a\StudentUsos\StudentUsos\StudentUsos: MONO_PATH=D:\a\StudentUsos\StudentUsos\StudentUsos\obj\Release\net9.0-android\android-x64\linked; MONO_ENV_OPTIONS= C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Runtime.AOT.win-x64.Cross.android-x64\9.0.2\Sdk\..\tools\mono-aot-cross.exe --debug --nollvm "--aot=asmwriter,temp-path=obj\Release\net9.0-android\android-x64\aot\x86_64\StudentUsos,mtriple=x86_64-linux-android,tool-prefix=C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\35.0.39\tools\binutils\bin\x86_64-linux-android-,outfile=obj\Release\net9.0-android\android-x64\aot\StudentUsos.dll.so,temp-path=obj\Release\net9.0-android\android-x64\StudentUsos.dll.tmp,ld-name=ld,ld-flags=--no-relax -s -z max-page-size=16384" "obj\Release\net9.0-android\android-x64\linked\StudentUsos.dll"
  
C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\35.0.39\targets\Microsoft.Android.Sdk.Aot.targets(110,5): error : Precompiling failed for D:\a\StudentUsos\StudentUsos\StudentUsos\obj\Release\net9.0-android\android-x64\linked\StudentUsos.dll with exit code -1073740940. [D:\a\StudentUsos\StudentUsos\StudentUsos\StudentUsos.csproj::TargetFramework=net9.0-android]
C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\35.0.39\targets\Microsoft.Android.Sdk.Aot.targets(110,5): error :  [D:\a\StudentUsos\StudentUsos\StudentUsos\StudentUsos.csproj::TargetFramework=net9.0-android]
  [1/168] CommunityToolkit.Maui.Core.dll -> CommunityToolkit.Maui.Core.dll.so
  [2/168] _Microsoft.Android.Resource.Designer.dll -> _Microsoft.Android.Resource.Designer.dll.so
  [3/168] CommunityToolkit.Mvvm.dll -> CommunityToolkit.Mvvm.dll.so
Copy link

We've found some similar issues:

If any of the above are duplicates, please consider closing this issue out and adding additional context in the original issue.

Note: You can give me feedback by 👍 or 👎 this comment.

@jfversluis jfversluis transferred this issue from dotnet/maui Mar 18, 2025
@jpobst
Copy link
Contributor

jpobst commented Mar 18, 2025

Can you please provide a binlog? This should contain the actual error message for us to investigate.

You can zip it up, as GitHub will not allow the .binlog extension for attachments.

@OvrBtn
Copy link
Author

OvrBtn commented Mar 18, 2025

Thanks for reply @jpobst , I have sent the binlog to your email.

@jpobst jpobst changed the title Precompiling failed [Android AOT] Precompiling failing in .NET 9 Mar 18, 2025
@jpobst
Copy link
Contributor

jpobst commented Mar 18, 2025

Hmm, it isn't writing any additional error information to the log like I would have expected.

I'm going to transfer this to dotnet/runtime as that team owns the Mono AOT compiler. Hopefully they have a better idea of what is going on!

@jpobst jpobst transferred this issue from dotnet/android Mar 18, 2025
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Mar 18, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Mar 18, 2025
@OvrBtn
Copy link
Author

OvrBtn commented Mar 18, 2025

Sooooo I had to spend quite some time doing git bisect and trial and error and I found the source of the issue

This causes the error

    [JsonSerializable(typeof(Secrets))]
    public partial class SecretsJsonContext : JsonSerializerContext
    { }

    public class Secrets
    {
        public string Url { get; init; } //<---------------
    }

But this works just fine

    [JsonSerializable(typeof(Secrets))]
    public partial class SecretsJsonContext : JsonSerializerContext
    { }

    public class Secrets
    {
        public string Url { get; set; }
    }

To conclude

  1. It works in .net 8 but not in .net 9
  2. It works when disabling AOT
  3. It works when doing JsonSerializer.Deserialize<Secrets>(json); instead of using Source Generator

So the issue is a combination of AOT + Source Generator + property with Init

I might need a drink after this

@teo-tsirpanis teo-tsirpanis added area-Codegen-AOT-mono and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Mar 21, 2025
@steveisok
Copy link
Member

/cc @lateralusX @BrzVlad

@BrzVlad
Copy link
Member

BrzVlad commented Mar 22, 2025

I suspect this is the same issue as with the other AOT compilation failures. A fix for it would be shipped in April, runtime version 9.0.4.

@steveisok steveisok removed the untriaged New issue has not been triaged by the area owner label Mar 22, 2025
@steveisok
Copy link
Member

@OvrBtn can you try this when the April servicing release comes out and let us know if it's fixed?

@steveisok
Copy link
Member

Actually, since you have a small repro, I can give it a spin and see if it resolved the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants