diff --git a/src/DnsClient/TaskExtensions.cs b/src/DnsClient/TaskExtensions.cs index a60fd1f2..40a7f057 100644 --- a/src/DnsClient/TaskExtensions.cs +++ b/src/DnsClient/TaskExtensions.cs @@ -15,6 +15,10 @@ public static async Task WithCancellation(this Task task, CancellationT onCancel(); } catch { } + + // observe the exception to avoid "System.AggregateException: A Task's exception(s) were + // not observed either by Waiting on the Task or accessing its Exception property." + task.ContinueWith(t => t.Exception); throw new OperationCanceledException(cancellationToken); } } @@ -22,4 +26,4 @@ public static async Task WithCancellation(this Task task, CancellationT return await task.ConfigureAwait(false); } } -} \ No newline at end of file +}