Bug 54323 - AppDomain.CurrentDomain.UnhandledException ExceptionObject stacktrace always null
Summary: AppDomain.CurrentDomain.UnhandledException ExceptionObject stacktrace always ...
Status: CONFIRMED
Alias: None
Product: Android
Classification: Xamarin
Component: General (show other bugs)
Version: 7.1 (C9)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2017-03-31 08:40 UTC by Saskia
Modified: 2017-07-07 15:54 UTC (History)
2 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test app with unhandled error bug (58.64 KB, application/x-zip-compressed)
2017-03-31 08:40 UTC, Saskia
Details

Description Saskia 2017-03-31 08:40:17 UTC
Created attachment 21087 [details]
Test app with unhandled error bug

The ExceptionObject in the UnhandledExceptionEventArgs never has a stacktrace (and other properties). Only the exception message is shown.

In the RaiseThrowableEventArgs of the UnhandledExceptionRaiser function the exception does contain all information.

I have tried some workarounds, without success.

This is the code (see attached test application):

		protected override void OnCreate(Bundle bundle)
		{
			TabLayoutResource = Resource.Layout.Tabbar;
			ToolbarResource = Resource.Layout.Toolbar;

			base.OnCreate(bundle);
			// Unhandled errors.
			AndroidEnvironment.UnhandledExceptionRaiser += AndroidEnvironment_UnhandledExceptionRaiser;
			AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;

			global::Xamarin.Forms.Forms.Init(this, bundle);
			LoadApplication(new App());
		}

		private void AndroidEnvironment_UnhandledExceptionRaiser(object sender, RaiseThrowableEventArgs args)
		{
			// Here the exception contains the stacktrace.
			string sTest = args.Exception.ToString();
			// This proposed workaraound causes error {System.NullReferenceException: Object reference not set to an instance of an object.}
//			typeof(System.Exception).GetField("stack_trace", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(args.Exception, null);
//			throw args.Exception;
		}

		private static void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs args)
		{
			// Here the stacktrace is always null. Tested on emulator and device.
			string sTest = args.ExceptionObject.ToString();
		}
Comment 1 Jon Douglas [MSFT] 2017-07-07 15:54:43 UTC
I am CONFIRMING this behavior based on the reproduction in https://bugzilla.xamarin.com/show_bug.cgi?id=54323#c0

Since I'm unsure of what should propagate with regards to this event handler, I'll leave it to be answered by someone else.

Thank you for the report!

Note You need to log in before you can comment on or make changes to this bug.