AOT failing on a third party nuget we are trying to AOT skip

Open
#112,192 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
28/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
android, csharp

Research direction

Start with Microsoft.Android.Sdk.Aot.targets at line 109 and the assertion reported at mono/metadata/metadata.c:1326. Reproduce using WW.Cad_Net6.0, the supplied Android AOT properties, and the WW, WW.Cad, and WW.Pdf assemblies. Done means a confirmed minimal reproduction and a documented fix or workaround for skipping the assemblies.

Written by the indexing model from the issue text.

Description

area-Codegen-AOT-mono needs-further-triage
Android framework version

net8.0-android

Affected platform version

SDK 8.0.300, Android 34.0.147/8.0.100

Description

We have a third party nuget that is failing during AOT - we are trying to skip the assembly but the AOT process still seems to hit an assertion exception and fails the build.

The nuget is,
<PackageReference Include="WW.Cad_Net6.0" Version="6.0.2023.11201" />

It requires a license to use at runtime, but building should be fine.

This is the AOT exceptions we are getting,

[68/176] System.Text.Json.dll -> System.Text.Json.dll.so
[WW.dll] Exec (with response file contents expanded) in /.../MyApp.Droid: MONO_PATH=/.../MyApp.Droid/obj/Release/net8.0-android/android-arm/linked: MONO_ENV_OPTIONS= /usr/local/share/dotnet/packs/Microsoft.NETCore.App.Runtime.AOT.osx-arm64.Cross.android-arm/8.0.12/Sdk/../tools/mono-aot-cross --debug --nollvm "--aot=asmwriter,temp-path=obj/Release/net8.0-android/android-arm/aot/armeabi-v7a/WW,profile-only,profile=/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.147/targets/dotnet.aotprofile,mtriple=armv7-linux-gnueabi,tool-prefix=/Users/iainstanford/Library/Developer/Xamarin/android-sdk-macosx/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-,outfile=obj/Release/net8.0-android/android-arm/aot/WW.dll.so,temp-path=obj/Release/net8.0-android/android-arm/WW.dll.tmp,ld-name=ld,ld-flags=-s" "obj/Release/net8.0-android/android-arm/linked/WW.dll"

[69/176] SQLite-net.dll -> SQLite-net.dll.so
1>Microsoft.Android.Sdk.Aot.targets(109,5): Error  : Precompiling failed for /.../MyApp.Droid/obj/Release/net8.0-android/android-arm/linked/WW.Pdf.dll with exit code 134.
Mono Ahead of Time compiler - compiling assembly /.../MyApp.Droid/obj/Release/net8.0-android/android-arm/linked/WW.Pdf.dll
AOTID E94E2877-B87E-4DA9-376B-B9104CE840C7
Using profile data file '/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.147/targets/dotnet.aotprofile'
Added 0 methods from profile.
* Assertion at /Users/runner/work/1/s/src/mono/mono/metadata/metadata.c:1326, condition `GINT_TO_UINT32(idx) < table_info_get_rows (t)' not met
1>Microsoft.Android.Sdk.Aot.targets(109,5): Error  : Precompiling failed for /.../MyApp.Droid/obj/Release/net8.0-android/android-arm/linked/WW.dll with exit code 134.
Mono Ahead of Time compiler - compiling assembly /.../MyApp.Droid/obj/Release/net8.0-android/android-arm/linked/WW.dll
AOTID 4B2F46CF-11F6-7444-044F-1FA8DCB045C4
Using profile data file '/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.147/targets/dotnet.aotprofile'
Added 0 methods from profile.
* Assertion at /Users/runner/work/1/s/src/mono/mono/metadata/metadata.c:1326, condition `GINT_TO_UINT32(idx) < table_info_get_rows (t)' not met
[WW.Cad.dll] Exec (with response file contents expanded) in /.../MyApp.Droid: MONO_PATH=/.../MyApp.Droid/obj/Release/net8.0-android/android-arm/linked: MONO_ENV_OPTIONS= /usr/local/share/dotnet/packs/Microsoft.NETCore.App.Runtime.AOT.osx-arm64.Cross.android-arm/8.0.12/Sdk/../tools/mono-aot-cross --debug --nollvm "--aot=asmwriter,temp-path=obj/Release/net8.0-android/android-arm/aot/armeabi-v7a/WW.Cad,profile-only,profile=/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.147/targets/dotnet.aotprofile,mtriple=armv7-linux-gnueabi,tool-prefix=/Users/iainstanford/Library/Developer/Xamarin/android-sdk-macosx/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-,outfile=obj/Release/net8.0-android/android-arm/aot/WW.Cad.dll.so,temp-path=obj/Release/net8.0-android/android-arm/WW.Cad.dll.tmp,ld-name=ld,ld-flags=-s" "obj/Release/net8.0-android/android-arm/linked/WW.Cad.dll"

1>Microsoft.Android.Sdk.Aot.targets(109,5): Error  : Precompiling failed for /.../MyApp.Droid/obj/Release/net8.0-android/android-arm/linked/WW.Cad.dll with exit code 134.
Mono Ahead of Time compiler - compiling assembly /.../MyApp.Droid/obj/Release/net8.0-android/android-arm/linked/WW.Cad.dll
AOTID 1352B6E5-2C41-6B8E-0FEA-E968AD743BCB
Using profile data file '/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.147/targets/dotnet.aotprofile'
Added 0 methods from profile.
* Assertion at /Users/runner/work/1/s/src/mono/mono/metadata/metadata.c:1326, condition `GINT_TO_UINT32(idx) < table_info_get_rows (t)' not met
[70/176] Xamarin.Android.Glide.dll -> Xamarin.Android.Glide.dll.so

We've tried the following to skip the assemblies but neither (and both) don't see to work...

  ...
  <AndroidLinkSkip>WW;WW.Cad;WW.Pdf</AndroidLinkSkip>
  ...

  <ItemGroup>
    <TrimmerRootAssembly Include="WW.Cad" RootMode="library" />
    <TrimmerRootAssembly Include="WW.Pdf" RootMode="library" />
    <TrimmerRootAssembly Include="WW" RootMode="library" />
  </ItemGroup>

This is our full set of properties for release builds with AOT

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
    <RuntimeIdentifiers>android-arm;android-arm64</RuntimeIdentifiers>
    <DebugSymbols>true</DebugSymbols>
    <MandroidI18n>west</MandroidI18n>
    <AndroidDexTool>d8</AndroidDexTool>
    <AndroidLinkTool>r8</AndroidLinkTool>
    <AndroidKeyStore>True</AndroidKeyStore>
    <AndroidSigningKeyStore>...</AndroidSigningKeyStore>
    <AndroidSigningStorePass>...</AndroidSigningStorePass>
    <AndroidSigningKeyAlias>...</AndroidSigningKeyAlias>
    <AndroidSigningKeyPass>...</AndroidSigningKeyPass>
    <AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
    <DefineConstants>TRACE</DefineConstants>
    <WarningLevel>4</WarningLevel>
    <RunAOTCompilation>true</RunAOTCompilation>
    <EnableLLVM>false</EnableLLVM>
    <AndroidUseDefaultAotProfile>true</AndroidUseDefaultAotProfile>
    <AndroidEnableProfiledAot>true</AndroidEnableProfiledAot>
    <AndroidUseAapt2>true</AndroidUseAapt2>
    <AndroidEnableSGenConcurrent>false</AndroidEnableSGenConcurrent>
    <AndroidLinkSkip>WW;WW.Cad;WW.Pdf</AndroidLinkSkip>
  </PropertyGroup>
Steps to Reproduce

Haven't been able to confirm in a small project,

  1. Add WW.Cad_Net6.0 nuget
  2. Enabled AOT
  3. Run build.
Did you find any workaround?

No response

Relevant log output

Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/runtime

All issues in dotnet/runtime

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.