HttpClient async methods (e.g. PostAsync, GetAsync etc.), if an exception is thrown, returns an AggregateException. Now an aggregate exception can contain a list of inner exceptions. My question is can someone provide an example where one of the async methods on an http client leads to more than one inner exception?
Is it safe to assume that although there is potentially a list of inner exceptions, in most cases you will only get one inner exception?
I'm aware of why they are being throw and how to handle it.
So to make this clearer, is it possible for a single call to an http client async method that throws an aggregate exception to have more than one exception in it's list of inner exceptions?
If you look inside
HttpClient.SendAsync
(which is the inner method being used to send all requests), you'll see that theTask
being created is a simpleTaskCompletionSource<HttpResponseMessage>
. Inside the calling method, it setsthis.SetTaskFaulted
multiple times, but always inside anif-else
block. What could potentially happen is that whenSetTaskFaulted
sets the exception, it could set off another exception:DisposeCancellationTokenAndTimer
internally disposes theCancellationToken
, and inside thefinally
block disposes the timer:The timer could potentially throw an exception from its
Dispose
method. Although im sure that's very rare.