Bug 49806 - TaskScheduler.UnobservedTaskException not called when an exception occurs in a Task.Run
Summary: TaskScheduler.UnobservedTaskException not called when an exception occurs in ...
Alias: None
Product: Runtime
Classification: Mono
Component: GC ()
Version: 4.6.0 (C8)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2016-12-13 12:01 UTC by softlion
Modified: 2017-10-11 17:44 UTC (History)
7 users (show)

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

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 on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description softlion 2016-12-13 12:01:06 UTC
TaskScheduler.UnobservedTaskException not called when an exception occurs in a Task.Run


  TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException;

 Task.Run(() =>
              throw new Exception("bug");

  private void TaskSchedulerOnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs unobservedTaskExceptionEventArgs)
         Log.Error("wsm","TaskScheduler.UnobservedTaskException from {0}: {1}", s.GetType(), e.Exception);


Microsoft Visual Studio Professional 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.6.02006

Installed Version: Professional

Xamarin (e738933)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android (72366f7)
Visual Studio extension to enable development for Xamarin.Android.

Xamarin.iOS (d93ae7e)
Visual Studio extension to enable development for Xamarin.iOS.
Comment 1 softlion 2016-12-13 12:01:56 UTC
Note that the Task.Run code is in a pcl library. Don't know if it is important to note.
Comment 2 Marek Safar 2016-12-15 17:42:40 UTC
Could you attach the app it reproduce the issue? I guess this is Android issue?

This looks like GC issue because all the logic is driven by Finalizer, see https://github.com/mono/mono/blob/af10ff717e227acc2c41a4dd82b435afa52e5936/mcs/class/referencesource/mscorlib/system/threading/Tasks/TaskExceptionHolder.cs#L101
Comment 3 softlion 2016-12-15 18:19:42 UTC
Yes it's on Android. I've not checked yet on iOS but there was an issue too. I'll try a repro.
Comment 4 Rodrigo Kumpera 2017-10-11 17:44:45 UTC
We have not received the requested information. If you are still experiencing this issue please provide all the requested information and reopen the bug report.

Thank you!