dotnet / dotnet/sdk

`ilc` fails with "Failed to load type System.ArraySegment'1 from assembly System.Runtime" on `android-arm64`, but not `android-x64`

Open
#54,013 2 comments 0 reactions 0 assignees View on GitHub
Area-ILLink untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Environment

- .NET SDK: 10.0.6 (release)
- ILC pack: `microsoft.dotnet.ilcompiler` 10.0.6 / `runtime.win-x64.microsoft.dotnet.ilcompiler`
10.0.6
- Host: Windows 11 (`win-x64` ilcompiler cross-compiling to Android)
- Target: `net10.0-android`, `RuntimeIdentifier=android-arm64`
- `PublishAot=true`, `PublishTrimmed=true`, `TrimMode=full`
- Project type: .NET MAUI Blazor Hybrid (`Sdk="Microsoft.NET.Sdk.Razor"`, `true`,
`OutputType=Exe`)
- `` is overridden to a shared base name (`System.ArraySegment` is only referenced
transitively through `System.Memory` / `System.Buffers`)

### What happens

`dotnet publish -c Release -f net10.0-android -p:RuntimeIdentifier=android-arm64
-p:UseNativeAot=true`:

```
EXEC : error Failed to load type 'System.ArraySegment`1' from assembly
'System.Runtime, Version=10.0.0.0, Culture=neutral, PublicKey=002400000480…'
C:\.ng\microsoft.dotnet.ilcompiler\10.0.6\build\Microsoft.NETCore.Native.targets(330,5):
error MSB3073: The command ""C:\.ng\runtime.win-x64.microsoft.dotnet.ilcompiler\10.0.6\tools\ilc"
@"…\artifacts\obj\App.Maui\release_net10.0-android_android-arm64\native\App.ilc.rsp""
exited with code 1.
```

The usual `IL3053` trim warnings on `Mono.Android` precede the ilc step; ilc itself then exits
non-zero after failing to load `System.ArraySegment` from the referenced `System.Runtime` ref
assembly.

### What works

Same project, same SDK/ilc version, same `UseNativeAot=true`, just `RuntimeIdentifier=android-x64` —
ilc completes, `.so` is generated, APK is produced. So this is specifically an **`android-arm64`**
runtime-pack gap.

### Cross-check against related issues

Looks like the same family as:

- #10587 — silent ILC compilation failure on Android (`need-info`)
- dotnet/runtime#76983 — `tls_CurrentThread` missing on android-arm64, long-standing
- dotnet/runtime#106748 — NativeAOT for Android still "Future" milestone

### Reproduction

No sample, but probably minimal .NET MAUI Blazor Hybrid project with `true` in
`Release|net10.0-android|android-arm64` that transitively references
`System.Memory.ReadOnlyMemory` / `ReadOnlySpan` (which `ArraySegment` is a sibling of in
the System.Runtime typemap) will trigger it. We hit it through `BlazorWebView` / `HttpClient` code
paths in the app.

### Workaround currently in use

We use CoreCLR+R2R on Android for now.

Happy to test a nightly ilcompiler / runtime-pack build.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.