Skip to content

[android] AppDomain.CurrentDomain.UnhandledException not working in .NET 5/6 #44526

@jonathanpeppers

Description

@jonathanpeppers

Description

I've been working on getting some integration tests working for Android in .NET 5/6, such as:

https://github.com/xamarin/xamarin-android/blob/5369da67a91c71aa646fd2642c71e519ae01cff9/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs#L63-L64

It appears that the AppDomain.CurrentDomain.UnhandledException event doesn't fire in an example such as:

public class MainActivity : Activity
{
	protected override void OnCreate (Bundle bundle)
	{
		base.OnCreate (bundle);

		SetContentView (Resource.Layout.Main);

		AppDomain.CurrentDomain.UnhandledException += (sender, e) => {
			Console.WriteLine ("# Unhandled Exception: sender={0}; e.IsTerminating={1}; e.ExceptionObject={2}",
				sender, e.IsTerminating, e.ExceptionObject);
		};
		throw new Exception ("CRASH");
	}
}

AppDomain.CurrentDomain.UnhandledException seems to work fine in a .NET 5 console app:

https://docs.microsoft.com/dotnet/api/system.appdomain.unhandledexception?view=net-5.0

Configuration

I was using a master build of Xamarin.Android, but I tried these .NET versions:

  • 5.0.100 GA
  • 6.0.100-alpha.1.20555.3

Regression?

No, Android is a new platform.

/cc @marek-safar @akoeplinger

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions