I am having a terrible time troubleshooting this issue. I'm also having a terrible time reproducing it consistently from one application to another.
Under certain circumstances, which I cannot seem to identify, making PUT and POST calls using the HttpClient results in the following exception.
An error occurred while sending the request.
Inner Exception:
The underlying connection was closed: An unexpected error occurred on a send.Inner Exception:
This operation cannot be performed on a completed asynchronous result object.
Everything seems to work with HTTP, this only happens on HTTPS.
Certificates are valid, but I have tried setting the ServicePointManager.ServerCertificateValidationCallback += (s, c, ch, es) => true;
I have tried setting client.DefaultRequestHeaders.ExpectContinue = false;
I have tried, what seems like a million, other things ranging from headers, authentication, etc.
Does anyone have any idea what else I can check, try, etc?
Code snippet:
// this is my registration in my IoC container...
var handler = new HttpClientHandler
{
UseDefaultCredentials = true,
Credentials = CredentialCache.DefaultNetworkCredentials,
};
var client = HttpClientFactory.Create(handler);
client.BaseAddress = new Uri(Properties.Settings.Default.BaseUrl);
client.DefaultRequestHeaders.Add("X-CustomHeader", "value");
// _client is constructor injected into my class...
var response = await _client.PutAsJsonAsync("api/resource/" + id, model).ConfigureAwait(false);
response.EnsureSuccessStatusCode(); // <-- never executes...
UPDATE:
If I take off the ConfigureAwait(false) it works fine.
Note, this is a WPF app, specifically, this is a Visual Studio extension. However, I do have an ASP.NET MVC