runtime icon indicating copy to clipboard operation
runtime copied to clipboard

[NET8] Precompilation Error (Exit Code -1073741819) when building on Release

Open takla21 opened this issue 2 years ago • 12 comments

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) 1 2

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.0 that contains viewmodels)
  • ProjectName.Business (library project net8.0 that contains business rule logic)
  • ProjectName.Access(library project net8.0 that 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

takla21 avatar Feb 20 '24 17:02 takla21

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

jonathanpeppers avatar Feb 20 '24 17:02 jonathanpeppers

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. image

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>

takla21 avatar Feb 20 '24 18:02 takla21

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

jonpryor avatar Feb 20 '24 19:02 jonpryor

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

takla21 avatar Feb 20 '24 19:02 takla21

@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>

takla21 avatar Feb 20 '24 20:02 takla21

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

takla21 avatar Feb 20 '24 20:02 takla21

@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

takla21 avatar Feb 21 '24 14:02 takla21

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.

hyigit-adelcon avatar Nov 19 '24 10:11 hyigit-adelcon

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?

l0gaw avatar Dec 20 '24 15:12 l0gaw

When I use version 8 it compiles without problems. I still cannot compile with version 9.

hyigit-adelcon avatar Dec 23 '24 06:12 hyigit-adelcon

/cc @vitek-karas

steveisok avatar Jul 20 '25 22:07 steveisok

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.

NXTwoThou avatar Jan 08 '26 17:01 NXTwoThou