Skip to content

NativeAOT: a fatal managed exception on the main thread leaves the process alive (propagateUncaughtException has no native implementation) #13141

Open

Description

@MartinZikmund

Android framework version

net10.0-android

Affected platform version

.NET SDK 10.0.401, Microsoft.Android.Sdk 36.1.69, PublishAot=true, android-x64 on an API 35 emulator (Google APIs Play Store x86_64 image). I have not tried arm64.

Description

With NativeAOT, an unhandled managed exception on the main thread does not terminate the app. The process stays alive (adb shell ps still lists it), the UI stays wherever it was, and the crash dialog never shows. The same app built without PublishAot dies as expected.

The managed exception is logged as a FATAL EXCEPTION: main from AndroidRuntime (a JavaProxyThrowable wrapping the managed exception), then logcat shows:

E ame.ZombieRepro: No implementation found for void mono.android.Runtime.propagateUncaughtException(java.lang.Thread, java.lang.Throwable) (tried Java_mono_android_Runtime_propagateUncaughtException and Java_mono_android_Runtime_propagateUncaughtException__Ljava_lang_Thread_2Ljava_lang_Throwable_2) - is the library loaded, e.g. System.loadLibrary?

propagateUncaughtException is declared native in src/java-runtime/java/mono/android/Runtime.java. The CoreCLR host exports it (src/native/clr/host/host-jni.cc, libnet-android.map.txt). I could not find a NativeAOT counterpart by code search (not stepped through, happy to be corrected). So the JNI lookup fails and the default handler never kills the process.

The same log line is pasted in a comment in tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs (the NativeAOT branch of AppWithStyleableUsageRuns), so the existing tests hit it too.

Impact: a startup crash looks like a hang. Anything that detects crashes by process death never sees one. We only found this because our CI waited out its whole job timeout.

Related: #10657 / #10658 (the CoreCLR equivalent, closed) and the NativeAOT TODO list #9784 (it mentions that AppDomain.CurrentDomain.UnhandledException is skipped under NativeAOT). I found no issue covering this symptom.

Steps to Reproduce

Verified on a blank app, no third-party packages.

  1. dotnet new android -n ZombieRepro
  2. In ZombieRepro.csproj add:
    <PublishAot>true</PublishAot>
    <RuntimeIdentifier>android-x64</RuntimeIdentifier>
  3. In MainActivity.OnCreate, before anything else: throw new InvalidOperationException("boom");
  4. dotnet publish -c Release -f net10.0-android (needs an NDK clang on PATH and -p:AndroidNdkDirectory=<ndk>), then adb install the -Signed.apk and launch it.
  5. Wait about 15 seconds. adb shell ps -A | grep -i zombie still lists the process (state S), and adb logcat -d | grep propagateUncaughtException shows the "No implementation found" line.
  6. Set PublishAot to false, rebuild, reinstall, launch: the process is gone after the same wait and only the FATAL EXCEPTION is logged.

Did you find any workaround?

Detect the crash from adb logcat -d -b crash (Process: <appid>, lines) instead of process death. An in-app option might be to hook AppDomain.CurrentDomain.UnhandledException and call Process.KillProcess(Process.MyPid()), but I haven't tried it, and #9784 says that event is skipped under NativeAOT.

Relevant log output

E AndroidRuntime: FATAL EXCEPTION: main
E AndroidRuntime: Process: com.companyname.ZombieRepro, PID: 4449
E AndroidRuntime: net.dot.jni.internal.JavaProxyThrowable: System.InvalidOperationException: boom
E AndroidRuntime:    at ZombieRepro.MainActivity.OnCreate(Bundle savedInstanceState) + 0x27
...
E ame.ZombieRepro: No implementation found for void mono.android.Runtime.propagateUncaughtException(java.lang.Thread, java.lang.Throwable) ...

Activity

  1. jonathanpeppers commented on Oct 20, 2026

    @jonathanpeppers
    Member

    Have you tried this in .NET 11? NativeAOT is generally more stable there.

  2. added
    need-infoIssues that need more information from the author.
    and removed
    needs-triageIssues that need to be assigned.
    on Oct 20, 2026
  3. dotnet-policy-service commented on Oct 20, 2026

    @dotnet-policy-service

    Hi @MartinZikmund. We have added the "need-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

  4. added this to the .NET 11 milestone on Oct 20, 2026
  5. tipa commented on Oct 21, 2026

    @tipa

    This also appears to affect .NET 11 RC2. The Java exception handler still calls propagateUncaughtException, but the NativeAOT runtime still lacks its implementation.

  6. added
    need-attentionA xamarin-android contributor needs to review
    and removed
    need-infoIssues that need more information from the author.
    on Oct 21, 2026
  7. added 2 commits that reference this issue on Oct 22, 2026
    af252f9
    c5c7452
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    need-attentionA xamarin-android contributor needs to review

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions