Don't call Result
, it's likely to cause issues on the best of days when using the async and await pattern
var apiResponse = await apiClient.GetAsync($"http://xxx/weatherforecast");
However, the problem is because you are trying to use a language feature associated with the await
keywords that requires an awaitable. The compiler dictates that to await
something it must satisfy certain constraints. An awaitable must implement the GetAwaiter
method, INotifyCompletion
, IsCompleted
and GetResult
method. Which is what the error message is describing.
This is due to the fact you have called the Result<T>
method which returns the result value of a task (in this case the result from the Task returned from GetAsync<Task<T>>
, your HttpResponseMessage
). You are then trying to await
it like it is a task / awaitable, which it is not.
In general, there are very few cases in the modern-era where calling Result
, or Wait
is actually a good idea.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…