System.InvalidOperationException: This instance has already started one or more requests. Properties can only be modified before sending the first request.
at System.Net.Http.HttpClientHandler.CheckDisposedOrStarted()
at System.Net.Http.HttpClientHandler.set_ServerCertificateCustomValidationCallback(Func`5 value)
at ModernHttpClient.NativeMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
at MyApp.DownloadService.<DownloadLargeFileInChunks>d__17.MoveNext()
Sample code:
_httpClient = new HttpClient(new NativeMessageHandler()
{
Timeout = TimeSpan.FromHours(12),
EnableUntrustedCertificates = true,
DisableCaching = true
});
var response = await _httpClient .GetAsync("SOME_VALID_URL", HttpCompletionOption.ResponseHeadersRead, CancellationToken.None);
// Making the second call using the same http client throws the exception.
var response2 = await _httpClient .GetAsync("SOME_VALID_URL_2", HttpCompletionOption.ResponseHeadersRead, CancellationToken.None);
The exception occurs on UWP but not in Android. When EnableUntrustedCertificates = false, the exception doesn't occur.
Sample code:
The exception occurs on UWP but not in Android. When EnableUntrustedCertificates = false, the exception doesn't occur.