I wrote some simple code with async await, but when I try to run it, the compiler throws a System.InvalidOperationException
.
The full error message is:
Unhandled Exception: System.InvalidOperationException: The character set provided in ContentType is invalid. Cannot read content as string using an invalid character set.
System.ArgumentException: 'ISO-8859-2' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.
The code:
class Program
{
static async Task Main(string[] args) => await asyncDoItAsync();
private static async Task<string> asyncDoItAsync()
{
HttpClient client = new HttpClient();
Task<string> url = client.GetStringAsync("http://google.pl");
while(!url.IsCompleted)
{
WhenWaiting();
}
string url_length = await url;
return url_length;
}
private static void WhenWaiting()
{
Console.WriteLine("Waiting ...");
Thread.Sleep(90);
}
}