Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 540
captncraig Avatar asked Nov 30 '22 22:11

captncraig


1 Answers

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

like image 64
ymzk_ms Avatar answered Dec 05 '22 10:12

ymzk_ms