Could not find Web Api method Content.ReadAsAsync, but compiles code

I use System.Net.Http.HttpClient to access the leisure service. This code compiles and works very well:

 var client = new HttpClient(); var result = client.GetAsync(ServiceUrl + "/whatever").Result; var content = result.Content.ReadAsAsync<StatusReport>().Result; 

However, the ReadAsAsync method is red in my IDE and intellisense cannot find it. I made sure to update all my nuget packages. The link and the added using statement for System.Net.Http.Formatting , but the error persists (and resharper tells me that the use statement is not used).

I'm not sure if this is a problem with visual studio 2012 or with resharper 7. Sometimes restarting Visual Studio helps, and sometimes not. I suspect that I might have some older version of the assembly reference, or something like that, but I updated everything I know and the problem is still intermittent.

What else can I try?

+4
source share
2 answers

Try to clear the cache. (ReSharper> Options> Environment> General> Clear Caches)

HttpClient is new in 4.5 AFAIK, and maybe your builds are cached from 4.0 or something else?

+5
source

You must add a link from Nuget "ASP.NET Web API 2 Client". Microsoft.AspNet.WebApi.Client

+13
source

Source: https://habr.com/ru/post/1444216/


All Articles