Skip to content

Exception information is lost for async code #7161

@trampster

Description

@trampster

Android application type

Classic Xamarin.Android (MonoAndroid12.0, etc.)

Affected platform version

VS2022

Description

When an unhandled exception occurs in async code instead of the actual type and stack trace you get the following:

[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object.
[mono-rt]   at Android.Runtime.JNINativeWrapper._unhandled_exception (System.Exception e) [0x0000e] in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:12 
[mono-rt]   at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V (_JniMarshal_PP_V callback, System.IntPtr jnienv, System.IntPtr klazz) [0x0001c] in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:23 
[mono-rt]   at (wrapper native-to-managed) Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(intptr,intptr)

It doesn't seem to matter what the original type was it's always shown as a NullReferenceException with that stack trace.

If your debugging then you get an Unhandled Exception popup that has no exception information except the wrong type (NullReferenceException) and no stack trace (it also doesn't stop on the location that threw the exception) if you then continue you get the [mono-rt] exception log from above.

This makes it almost impossible to find out/debug the problem as all relevant information is lost.

Steps to Reproduce

  1. Create a new Xamarin.Forms project
  2. Put the following code into the MainActivity.OnCreate
     await Task.Delay(1000);
     throw new InvalidOperationException("This exception info should not be lost");
  1. Run

Did you find any workaround?

no

Relevant log output

No response

Metadata

Metadata

Labels

Area: Mono.AndroidIssues with the Android API binding (Mono.Android.dll).

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions