[英]Web Api Content.ReadAsAsync method not found, but code compiles
I am using System.Net.Http.HttpClient
to access a rest service. 我正在使用
System.Net.Http.HttpClient
来访问休息服务。 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. 但是,我的IDE中的
ReadAsAsync
方法显示为红色,而intellisense无法找到它。 I have made sure to update all of my nuget packages. 我确保更新了所有的nuget包。 Referenced and added using statement for
System.Net.Http.Formatting
, but error persists (and resharper tells me the using statement is unused). 引用并添加了使用
System.Net.Http.Formatting
语句,但错误仍然存在(并且resharper告诉我using语句未使用)。
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. 我不确定这是视觉工作室2012或resharper 7的问题。有时重启视觉工作室有帮助,有时它没有。 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". 您必须添加Nuget“ASP.NET Web API 2 Client”的引用。 Microsoft.AspNet.WebApi.Client
Microsoft.AspNet.WebApi.Client
Try clearing your resharper cache. 尝试清除resharper缓存。 (ReSharper > Options > Environment > General > Clear Caches)
(ReSharper>选项>环境>常规>清除缓存)
HttpClient is new in 4.5 AFAIK and maybe your assemblies are cached from 4.0 or something? HttpClient是4.5 AFAIK中的新功能,也许你的程序集是从4.0或其他东西缓存的?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.