C#: Error – ‘System.Net.Http.HttpContent’ does not contain a definition for ‘ReadAsAsync’ and no extension method


I was working with HttpClient class to connect to external REST API’s from C# code and was implementing solution with asynchronous programming(Async / Await). Since class library project already have reference of System.Net.Http but I was having issue with extension method ReadAsAsync<T>()

'HttpContent' does not contain a definition for 'ReadAsAsync' and no extension method 
'ReadAsAsync' accepting a first argument of type 'HttpContent' could be found 
(are you missing a using directive or an assembly reference?)



ReadAsAsync is declared in the class HttpContentExtensions, which is in the namespace System.Net.Http in the library System.Net.Http.Formatting.

Right click on project and click Add a reference option, then go to Extensions from 
Assemblies tab and choose System.Net.Http.Formatting. If its not there then add 
manually this assembly, which is also available in the folder:
C:\Program Files\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies 



Alternate Solution:

Execute below command in NUGET console, make sure command is executed only relevant to that project

Install-Package Microsoft.AspNet.WebApi.Client



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s