dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.94k stars 533 forks source link

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

Open takla21 opened 9 months ago

takla21 commented 9 months ago

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:

Dependencies: ProjectName.Mobile -> ProjectName.Presentation ProjectName.Windows -> ProjectName.Presentation

ProjectName.Presentation -> ProjectName.Business -> ProjectName.Access

Steps to Reproduce

Did you find any workaround?

N/A

Relevant log output

No response

jonathanpeppers commented 9 months ago

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

takla21 commented 9 months ago

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>
jonpryor commented 9 months ago

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

takla21 commented 9 months ago

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 commented 9 months ago

@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 commented 9 months ago

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 commented 9 months ago

@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

hyigit-adelcon commented 1 week ago

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.