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

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

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 54323 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

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;

			// 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!