diff --git a/src/Mono.Android/Android.Runtime/JNIEnv.cs b/src/Mono.Android/Android.Runtime/JNIEnv.cs index 064c73c6f72..6cdd1545626 100644 --- a/src/Mono.Android/Android.Runtime/JNIEnv.cs +++ b/src/Mono.Android/Android.Runtime/JNIEnv.cs @@ -241,7 +241,12 @@ static void ManualJavaObjectDispose (Java.Lang.Object obj) GC.SuppressFinalize (obj); } - static Action mono_unhandled_exception = null!; +#if NETCOREAPP + internal static Action mono_unhandled_exception = monodroid_debugger_unhandled_exception; +#else // NETCOREAPP + internal static Action mono_unhandled_exception = null!; +#endif // NETCOREAPP + #if !NETCOREAPP static Action AppDomain_DoUnhandledException = null!; #endif // ndef NETCOREAPP @@ -695,6 +700,11 @@ public static string GetClassNameFromInstance (IntPtr jobject) [MethodImplAttribute(MethodImplOptions.InternalCall)] static extern unsafe IntPtr monodroid_typemap_managed_to_java (Type type, byte* mvid); +#if NETCOREAPP + [MethodImplAttribute(MethodImplOptions.InternalCall)] + static extern unsafe void monodroid_debugger_unhandled_exception (Exception e); +#endif // NETCOREAPP + internal static void LogTypemapTrace (StackTrace st) { string? trace = st.ToString ()?.Trim (); diff --git a/src/Mono.Android/Android.Runtime/JNINativeWrapper.cs b/src/Mono.Android/Android.Runtime/JNINativeWrapper.cs index eab1f812555..88b1e3b110b 100644 --- a/src/Mono.Android/Android.Runtime/JNINativeWrapper.cs +++ b/src/Mono.Android/Android.Runtime/JNINativeWrapper.cs @@ -21,6 +21,9 @@ static void get_runtime_types () if (mono_unhandled_exception_method == null) AndroidEnvironment.FailFast ("Cannot find System.Diagnostics.Debugger.Mono_UnhandledException"); #endif +#if NETCOREAPP + mono_unhandled_exception_method = JNIEnv.mono_unhandled_exception.Method; +#endif // NETCOREAPP exception_handler_method = typeof (AndroidEnvironment).GetMethod ( "UnhandledException", BindingFlags.NonPublic | BindingFlags.Static); if (exception_handler_method == null) diff --git a/src/monodroid/jni/monodroid-glue-internal.hh b/src/monodroid/jni/monodroid-glue-internal.hh index f2b5a48c835..1e567f30a64 100644 --- a/src/monodroid/jni/monodroid-glue-internal.hh +++ b/src/monodroid/jni/monodroid-glue-internal.hh @@ -286,6 +286,9 @@ namespace xamarin::android::internal static MonoReflectionType* typemap_java_to_managed (MonoString *java_type_name); static const char* typemap_managed_to_java (MonoReflectionType *type, const uint8_t *mvid); +#if defined (NET6) + static void monodroid_debugger_unhandled_exception (MonoException *ex); +#endif #if defined (DEBUG) void set_debug_env_vars (void); diff --git a/src/monodroid/jni/monodroid-glue.cc b/src/monodroid/jni/monodroid-glue.cc index 923a0efd6b5..2b07d43cb8c 100644 --- a/src/monodroid/jni/monodroid-glue.cc +++ b/src/monodroid/jni/monodroid-glue.cc @@ -1001,6 +1001,14 @@ MonodroidRuntime::lookup_bridge_info (MonoDomain *domain, MonoImage *image, cons } #endif // ndef NET6 +#if defined (NET6) +void +MonodroidRuntime::monodroid_debugger_unhandled_exception (MonoException *ex) +{ + mono_debugger_agent_unhandled_exception (ex); +} +#endif + void MonodroidRuntime::init_android_runtime ( #if !defined (NET6) @@ -1011,6 +1019,7 @@ MonodroidRuntime::init_android_runtime ( mono_add_internal_call ("Java.Interop.TypeManager::monodroid_typemap_java_to_managed", reinterpret_cast(typemap_java_to_managed)); mono_add_internal_call ("Android.Runtime.JNIEnv::monodroid_typemap_managed_to_java", reinterpret_cast(typemap_managed_to_java)); #if defined (NET6) + mono_add_internal_call ("Android.Runtime.JNIEnv::monodroid_debugger_unhandled_exception", reinterpret_cast (monodroid_debugger_unhandled_exception)); mono_add_internal_call ("Android.Runtime.JNIEnv::monodroid_unhandled_exception", reinterpret_cast(monodroid_unhandled_exception)); #endif // def NET6