Merge pull request #901 from Blewzman/FixAggregateExceptionGetBaseException
[mono.git] / mcs / class / corlib / System.Runtime.CompilerServices / TaskAwaiter.cs
index 80b64cb56e841ac167288eb742725eca27a91d6b..07110cf2b75406173394e05f1380e1533c9359a5 100644 (file)
@@ -62,15 +62,18 @@ namespace System.Runtime.CompilerServices
 
                internal static Exception HandleUnexpectedTaskResult (Task task)
                {
+                       var slot = task.ExceptionSlot;
                        switch (task.Status) {
                        case TaskStatus.Canceled:
                                // Use original exception when we have one
-                               if (task.ExceptionSlot.Exception != null)
+                               if (slot.Exception != null)
                                        goto case TaskStatus.Faulted;
 
                                return new TaskCanceledException (task);
                        case TaskStatus.Faulted:
-                               return task.ExceptionSlot.Exception.InnerException;
+                               // Mark the exception as observed when GetResult throws
+                               slot.Observed = true;
+                               return slot.Exception.InnerException;
                        default:
                                throw new ArgumentException (string.Format ("Unexpected task `{0}' status `{1}'", task.Id, task.Status));
                        }