"HttpResponseMessage' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter'"
"HttpResponseMessage' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter'"
我在C#中有一个测试web api的xUnit方法。\n
[Fact] public async Task GetWeatherForecast() { var apiClient = new HttpClient(); var apiResponse = await apiClient.GetAsync($"http://xxx/weatherforecast").Result; Assert.True(apiResponse.IsSuccessStatusCode); }
\n但是出现了错误`HttpResponseMessage\' does not contain a definition for \'GetAwaiter\' and no accessible extension method \'GetAwaiter\'`。如果我移除`async Task`和`await`,它可以成功运行。