why can't you use IHttpClientFactory? You can make the HttpClient async call sync with .GetAwaiter().GetResult().
var buffer = httpClient.GetByteArrayAsync(blobUrl).GetAwaiter().GetResult();
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
In an event that is called synchronously, so I can't use await (so no IHttpClientFactory
), what is the correct way to read the contents of a file.
I am using the following, and it works. But the compiler is telling me I should not use WebClient
.
And to repeat, I have no choice in the matter - this cannot be an async method.
public byte[]? GetContent(IBlobService blobService, string blobUrl)
{
using (var client = new WebClient())
{
return client.DownloadData(blobUrl);
}
}
why can't you use IHttpClientFactory? You can make the HttpClient async call sync with .GetAwaiter().GetResult().
var buffer = httpClient.GetByteArrayAsync(blobUrl).GetAwaiter().GetResult();