I receive an Exception (Method not found) when attempting to call the following method.
public static async Task<HttpResponseMessage> Send(HttpRequestMessage request) {
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
HttpResponseMessage response = await HttpClient.SendAsync(request);
if (response.IsSuccessStatusCode)
return response;
throw new HttpResponseException(response);
}
The failure occurs because of the explicit exception throw on the last line.
If I change
throw new HttpResponseException(response);
to
return null;
the method is found.
I'd like to understand the specific reason the method cannot be found when attempting to throw the exception (The generic / async / TaskAwaiter is not able to match all code paths?).
Can you recommend how I can code the method in a way that I can properly throw the exception?
Thanks for your help!