'System.Net.Http.HttpContent' does not contain a definition for 'ReadAsAsync' and no extension method
After a long struggle, I found the solution.
Solution: Add a reference to System.Net.Http.Formatting.dll
. This assembly is also available in the C:\Program Files\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies folder.
The method ReadAsAsync
is an extension method declared in the class HttpContentExtensions
, which is in the namespace System.Net.Http
in the library System.Net.Http.Formatting
.
Reflector came to rescue!
Make sure that you have installed the correct NuGet package
in your console application:
<package id="Microsoft.AspNet.WebApi.Client" version="4.0.20710.0" />
and that you are targeting at least .NET 4.0.
This being said, your GetAllFoos
function is defined to return an IEnumerable<Prospect>
whereas in your ReadAsAsync
method you are passing IEnumerable<Foo>
which obviously are not compatible types.
Install-Package Microsoft.AspNet.WebApi.Client
- if you unable to find assembly reference from when (Right click on reference ->add required assembly)
try this
Package manager console
Install-Package System.Net.Http.Formatting.Extension -Version 5.2.3
and then add by using add reference .