简体   繁体   中英

Web Api Content.ReadAsAsync method not found, but code compiles

I am using System.Net.Http.HttpClient to access a rest service. This code compiles and runs just fine:

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

However the ReadAsAsync method is colored red in my IDE, and intellisense cannot find it. I have made sure to update all of my nuget packages. Referenced and added using statement for System.Net.Http.Formatting , but error persists (and resharper tells me the using statement is unused).

I am not sure if this is a problem with visual studio 2012, or with resharper 7. Sometimes restarting visual studio helps, and sometimes it doesn't. I suspect I may have some older version of some assembly referenced, or something like that, but I have updated everything I know how and the problem is still intermittent.

What else can I try?

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

Try clearing your resharper cache. (ReSharper > Options > Environment > General > Clear Caches)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM