[NET8] Precompilation Error (Exit Code -1073741819) when building on Release
Android application type
.NET Android (net7.0-android, net8.0-android, etc.)
Affected platform version
NET 8.0.100, 8.0.200
Description
I am currently migrating a project from net7.0-android to net8.0-android. While the project compiles fine in debug mode, building in release mode fails with the following error:
4>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.79\targets\Microsoft.Android.Sdk.Aot.targets(109,5): error : Precompiling failed for C:\{pathToProject}\ProjectName.Mobile\obj\Release\net8.0-android\android-x64\linked\ProjectName.Business.dll with exit code -1073741819.
4>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.79\targets\Microsoft.Android.Sdk.Aot.targets(109,5): error :
Here are binlogs as screenshots (confidential stuff redacted)
Context: Our project structure is as follows:
- ProjectName.Mobile (mobile head
net8.0-android,net8.0-ios) - ProjectName.Windows (windows head)
- ProjectName.Presentation (library project
net8.0that contains viewmodels) - ProjectName.Business (library project
net8.0that contains business rule logic) - ProjectName.Access(library project
net8.0that contains API call logic)
Dependencies: ProjectName.Mobile -> ProjectName.Presentation ProjectName.Windows -> ProjectName.Presentation
ProjectName.Presentation -> ProjectName.Business -> ProjectName.Access
Steps to Reproduce
- Build on Release
Did you find any workaround?
N/A
Relevant log output
No response
Can you share a .binlog of the failure? https://aka.ms/binlog
Is there anything special about ProjectName.Access.dll? Does it have missing assembly references? Does the AOT compiler log anything else besides the exit code? exit code -1073741819
I'll try to reproduce this issue on another project outside of this one first before giving you an actual binlog to avoid sending sensitive data related to the project I'm working on. That's why I've provided you screenshots of those binlog.
I'm only seeing errors with the exit code
The ProjectName.Access.dll is generated from this net8 project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>12.0</LangVersion>
<RootNamespace>ProjectName.DataAccess</RootNamespace>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DynamicData" Version="7.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.1.0" />
<PackageReference Include="Reactive.Annex" Version="0.6.0-dev.50" />
<PackageReference Include="RequestsSignature.HttpClient" Version="2.0.0" />
<PackageReference Include="Uno.CodeGen" Version="2.0.0-dev.10" />
<PackageReference Include="Refit" Version="7.0.0" />
<PackageReference Include="ReviewService.Abstractions" Version="1.0.0" />
<PackageReference Include="System.Text.Json" Version="7.0.3" />
<PackageReference Include="MallardMessageHandlers" Version="0.2.0-dev.21" />
<PackageReference Include="Nventive.Persistence.Reactive" Version="0.4.0-dev.36" />
<PackageReference Include="Nventive.Persistence" Version="0.4.0-dev.36" />
<PackageReference Include="System.Reactive" Version="5.0.0" />
<PackageReference Include="GeneratedSerializers.Json" Version="1.0.0-dev.34" />
<!-- There are also internal nuget packages (they're all targeting .net6.0) referenced here -->
</ItemGroup>
</Project>
Exit code -1073741819 is 0xc0000005 which is Access Violation. In all likelihood, mono-aot-cross.exe is crashing.
@takla21: Does it consistently crash on the same assembly?
Is there some way for us to get a copy of the assembly/assemblies which consistently cause the build failure?
/cc @steveisok
Ok I'm still working on finding a way to send you bindlog, but I just found out that the bug happens when <AndroidEnableProfiledAot>True</AndroidEnableProfiledAot> is set
@jonpryor yes, it's always the same assembly that causes the failure. It comes from one of the projects mentioned above. Here's its csproj content
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>11.0</LangVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ProjectName.Access\ProjectName.Access.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.11.54" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="6.0.2" />
<PackageReference Include="Parasol.Environment.Hardware" Version="0.40.5" />
<PackageReference Include="Parasol.Presentation" Version="0.40.5" />
<PackageReference Include="Parasol.Storage.Biometry" Version="0.40.5" />
<PackageReference Include="Uno.CodeGen" Version="2.0.0-dev.10" />
<PackageReference Include="Parasol.Feeds" Version="0.40.5" />
<PackageReference Include="MessageDialogService" Version="0.5.0-dev.54" />
</ItemGroup>
</Project>
I also forgot to list all workloads that I'm using locally
Installed Workload Id Manifest Version Installation Source
-------------------------------------------------------------------------------------
maui-windows 8.0.6/8.0.100 VS 17.10.34607.79, VS 17.7.34302.85
maccatalyst 17.2.8022/8.0.100 VS 17.10.34607.79, VS 17.7.34302.85
ios 17.2.8022/8.0.100 VS 17.10.34607.79, VS 17.7.34302.85
android 34.0.79/8.0.100 VS 17.10.34607.79, VS 17.7.34302.85
maui-android 8.0.6/8.0.100 VS 17.7.34302.85
maui-maccatalyst 8.0.6/8.0.100 VS 17.7.34302.85
maui-ios 8.0.6/8.0.100 VS 17.7.34302.85
@jonpryor @jonathanpeppers I sent you both the assembly + binlog to the email associated on your github account. Hopefully it will help identify the issue here
In my experience, I got this error after upgrading to .NET 9.
MauiApp1 net9.0-android failed with 1 error(s) (29,9s)
C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\35.0.7\targets\Microsoft.Android.Sdk.Aot.targets(110,5): error :
Precompiling failed for C:\Users\...\Desktop\MauiApp1\MauiApp1\obj\Release\net9.0-android\android-x64\linked\Sy
stem.Private.Windows.Core.dll with exit code -1073741819.
Mono Ahead of Time compiler - compiling assembly C:\Users\...\Desktop\MauiApp1\MauiApp1\obj\Release\net9.0-andr
oid\android-x64\linked\System.Private.Windows.Core.dll
AOTID 768B782E-1B56-15E4-E61B-A17BB6559ED4
Using profile data file 'C:\Users\...\.nuget\packages\microsoft.maui.controls.build.tasks\9.0.10\buildTransitiv
e\netstandard2.0\maui.aotprofile'
Using profile data file 'C:\Users\...\.nuget\packages\microsoft.maui.controls.build.tasks\9.0.10\buildTransitiv
e\netstandard2.0\maui-blazor.aotprofile'
Added 0 methods from profile.
Added 0 methods from profile.
Could not load signature of System.Windows.Forms.Nrbf.SerializationRecordExtensions+TryGetDelegate:BeginInvoke due
to: Could not load file or assembly 'System.Formats.Nrbf, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13
ffcd2ddd51' or one of its dependencies.
After a step-by-step investigation, I found out that the error was caused by the System.Drawing.Common library. When I disabled the reference below, the Android build went smoothly.
<PackageReference Include="System.Drawing.Common" Version="9.0.0" />
Maybe it will help you too.
In my experience, I got this error after upgrading to .NET 9.
MauiApp1 net9.0-android failed with 1 error(s) (29,9s) C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\35.0.7\targets\Microsoft.Android.Sdk.Aot.targets(110,5): error : Precompiling failed for C:\Users\...\Desktop\MauiApp1\MauiApp1\obj\Release\net9.0-android\android-x64\linked\Sy stem.Private.Windows.Core.dll with exit code -1073741819. Mono Ahead of Time compiler - compiling assembly C:\Users\...\Desktop\MauiApp1\MauiApp1\obj\Release\net9.0-andr oid\android-x64\linked\System.Private.Windows.Core.dll AOTID 768B782E-1B56-15E4-E61B-A17BB6559ED4 Using profile data file 'C:\Users\...\.nuget\packages\microsoft.maui.controls.build.tasks\9.0.10\buildTransitiv e\netstandard2.0\maui.aotprofile' Using profile data file 'C:\Users\...\.nuget\packages\microsoft.maui.controls.build.tasks\9.0.10\buildTransitiv e\netstandard2.0\maui-blazor.aotprofile' Added 0 methods from profile. Added 0 methods from profile. Could not load signature of System.Windows.Forms.Nrbf.SerializationRecordExtensions+TryGetDelegate:BeginInvoke due to: Could not load file or assembly 'System.Formats.Nrbf, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13 ffcd2ddd51' or one of its dependencies.After a step-by-step investigation, I found out that the error was caused by the System.Drawing.Common library. When I disabled the reference below, the Android build went smoothly.
<PackageReference Include="System.Drawing.Common" Version="9.0.0" />Maybe it will help you too.
I'm also using this package, could you let me know what you did to workaround this?
When I use version 8 it compiles without problems. I still cannot compile with version 9.
/cc @vitek-karas
Exact same issue with a brand new pretty simple .NET 10 MAUI Blazor Hybrid project I started a week ago. Can compile debug, as soon as I switch to release I get System.Formats.Nrbf error until I downgrade System.Drawing.Common from 10.0.2 to 8.0.22.
10.0.2 fail 10.0.1 fail 10.0.0 fail 9.0.11 fail 9.0.10 fail 9.0.9 fail 9.0.8 fail 9.0.7 fail 9.0.6 fail 9.0.5 fail 9.0.4 fail 9.0.3 fail 9.0.2 fail 9.0.1 fail 9.0.0 fail 8.0.22 success
https://github.com/dotnet/maui/issues/27057 was "Closing this as the binary formatter has been removed and is now unsupported."
The fact I can use 10.0.2 with debug but have to use 8.0.22 for release is extremely hard to explain to my boss. Could someone give me a good rundown as to why this issue exists and hasn't been fixed for two full .NET releases?
Adding a package(System.Formats.Nrbf ) that's unnecessary for debug and has had vulnerability issues doesn't feel like the right way to approach the situation.