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?)
Solution:
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
thank u so much
LikeLike
Thanks. It was helpful
LikeLike