@@ -242,7 +242,9 @@ static void ManualJavaObjectDispose (Java.Lang.Object obj)
242242 }
243243
244244 static Action < Exception > mono_unhandled_exception = null ! ;
245+ #if ! NETCOREAPP
245246 static Action < AppDomain , UnhandledExceptionEventArgs > AppDomain_DoUnhandledException = null ! ;
247+ #endif
246248
247249 static void Initialize ( )
248250 {
@@ -253,6 +255,7 @@ static void Initialize ()
253255 mono_unhandled_exception = ( Action < Exception > ) Delegate . CreateDelegate ( typeof ( Action < Exception > ) , mono_UnhandledException ) ;
254256 }
255257
258+ #if ! NETCOREAPP
256259 if ( AppDomain_DoUnhandledException == null ) {
257260 var ad_due = typeof ( AppDomain )
258261 . GetMethod ( "DoUnhandledException" ,
@@ -265,8 +268,14 @@ static void Initialize ()
265268 typeof ( Action < AppDomain , UnhandledExceptionEventArgs > ) , ad_due ) ;
266269 }
267270 }
271+ #endif
268272 }
269273
274+ #if NETCOREAPP
275+ [ DllImport ( AndroidRuntime . InternalDllName , CallingConvention = CallingConvention . Cdecl ) ]
276+ extern static void monodroid_unhandled_exception ( Exception javaException ) ;
277+ #endif
278+
270279 internal static void PropagateUncaughtException ( IntPtr env , IntPtr javaThreadPtr , IntPtr javaExceptionPtr )
271280 {
272281 if ( ! PropagateExceptions )
@@ -287,14 +296,18 @@ internal static void PropagateUncaughtException (IntPtr env, IntPtr javaThreadPt
287296 try {
288297 var jltp = javaException as JavaProxyThrowable ;
289298 Exception ? innerException = jltp ? . InnerException ;
290- var args = new UnhandledExceptionEventArgs ( innerException ?? javaException , isTerminating : true ) ;
291299
292300 Logger . Log ( LogLevel . Info , "MonoDroid" , "UNHANDLED EXCEPTION:" ) ;
293301 Logger . Log ( LogLevel . Info , "MonoDroid" , javaException . ToString ( ) ) ;
294302
303+ #if ! NETCOREAPP
304+ var args = new UnhandledExceptionEventArgs ( innerException ?? javaException , isTerminating : true ) ;
295305 // Disabled until Linker error surfaced in https://github.com/xamarin/xamarin-android/pull/4302#issuecomment-596400025 is resolved
296306 //AppDomain.CurrentDomain.DoUnhandledException (args);
297307 AppDomain_DoUnhandledException ? . Invoke ( AppDomain . CurrentDomain , args ) ;
308+ #else
309+ monodroid_unhandled_exception ( innerException ?? javaException ) ;
310+ #endif
298311 } catch ( Exception e ) {
299312 Logger . Log ( LogLevel . Error , "monodroid" , "Exception thrown while raising AppDomain.UnhandledException event: " + e . ToString ( ) ) ;
300313 }
0 commit comments