Bug 17015 - TaskScheduler.UnobservedTaskException raised for trapped exceptions
Summary: TaskScheduler.UnobservedTaskException raised for trapped exceptions
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: master
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Marek Safar
Depends on:
Reported: 2014-01-01 22:28 UTC by Greg Shackles
Modified: 2014-01-29 12:50 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 Greg Shackles 2014-01-01 22:28:57 UTC
TaskScheduler.UnobservedTaskException is still being raised even when the exception is trapped. This is working in the stable channel, and had been working in the alpha channel until recently, so I'm guessing it's a recent change. 

This is reproducible in Xamarin.iOS 7.0.6, and works correctly in 7.0.4.

Here's a simple repro:


using System;
using System.Threading.Tasks;
using MonoTouch.UIKit;

namespace UnhandledExceptionRepro
    public partial class UnhandledExceptionReproViewController : UIViewController
        public override async void ViewDidLoad()
            TaskScheduler.UnobservedTaskException += (sender, e) =>
                if (e.Exception != null)
                    InvokeOnMainThread(() =>
                        new UIAlertView("unobserved task exception", e.Exception.Message, null, "Ok", null).Show());

                await getResult();
            catch (Exception ex)
                new UIAlertView("trapped exception", ex.Message, null, "Ok", null).Show();

        private async Task getResult()
            await Task.Delay(10);

            throw new Exception("boom");
Comment 1 Sadik Ali 2014-01-02 08:57:36 UTC
I have verified this issue and getting TaskScheduler.UnobservedTaskException exception with current build, following are the verified steps:

1. Created a sample iOS (iPhone single view application)
2. Add above code into view controller cs file.
3. Debug application.

Refer screen shot: http://screencast.com/t/asl6xhf12

Current Build:
All Mac
XS 4.2.3 (build 23)
X iOs

Also I have verified on stable build, working fine.

Stables build:
All Mac
XS 4.2.2 (build 2)
X iOs
Comment 2 Marek Safar 2014-01-06 12:20:54 UTC
Fixed in mono master
Comment 3 Rolf Bjarne Kvinge [MSFT] 2014-01-07 12:29:54 UTC
Fix pushed to the monotouch 7.0.6 branch:

mono/monotouch-7.0.6-branch: 2007e2b9c414049ce229716e499ee42492733c9a
monotouch/monotouch-7.0.6-branch: 9ec960a2e74314630ed162f9221e6c86104f7e0e

monotouch/master: c0d6d27272e50f4248f8931f9971e087087bfc93
Comment 4 PJ 2014-01-14 12:46:07 UTC
Using Xamarin.iOS, the exception is properly trapped. See: http://screencast.com/t/uufCsj9v

Comment 5 Greg Shackles 2014-01-29 10:27:18 UTC
There's no mention of this fix in the new 7.0.6 maintenance release. Is it included?
Comment 6 Rolf Bjarne Kvinge [MSFT] 2014-01-29 12:50:38 UTC
Yes, this is included in the 7.0.6 release.