MarkF
MarkF

Reputation: 962

System.Net.Http missing?

I am trying to run Test.aspx:

<%@ Page language="c#" EnableViewState="true" ContentType="text/html" Async="true" %>

<script language="C#" runat="server">

    void Page_Load(Object Src, EventArgs E )
    {
        RegisterAsyncTask(new PageAsyncTask(BindData));
    }

    private async System.Threading.Tasks.Task BindData()
    {
        Response.Write("Hello?<br /><br />");

        using (System.Net.Http.HttpClient httpClient = new System.Net.Http.HttpClient())
        {
            Response.Write(await httpClient.GetStringAsync("http://www.google.com"));
        }

        Response.Write("<br /><br />Is this thing on?<br /><br />");
    }

</script>

and getting this error:

Test.aspx(14): error CS0234: The type or namespace name 'Http' does not exist in the namespace 'System.Net' (are you missing an assembly reference?)

The System.Net.Http.dll assembly is in

C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies

and in IIS Manager the Basic Settings' Application Pool is ASP.NET v4.0 (Integrated). Has anyone run into this?

UPDATE: I installed .Net 4.5.2 and added the following web.config

<configuration>
  <system.web>
    <httpRuntime targetFramework="4.5" />
   <compilation>
      <assemblies>
         <add assembly="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      </assemblies>
   </compilation>
  </system.web>

</configuration>

and it worked.

Upvotes: 4

Views: 21759

Answers (4)

Ned
Ned

Reputation: 1207

In my case, the issue started occurring after upgrading to .NET Framework 4.7.2. I found out that Nuget package for System.Net.Http is no longer recommended. Here are workarounds:

Upvotes: 1

Er Suman G
Er Suman G

Reputation: 691

I've tried this highly suggested solution (I found this as accepted answer in many similar questions here in SO)

on Web.Config write this and rebuild the solution

<system.web>
    <compilation debug="true" targetFramework="4.0" />
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
       <add assembly="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      </assemblies>
    </compilation>
</system.web>

But unfortunately, I've no luck with this. At last, I've found a solution which works for me and saved my day :)

  1. Right-click the References folder > Add Reference...
  2. Expand Assemblies on the left side of the window and select Framework.
  3. Scroll to and select System.Net.Http in the list of assemblies. Make sure the box next to System.Net.Http is checked, then click OK.
  4. Rebuild the project.

Upvotes: 1

Muhammad Awais
Muhammad Awais

Reputation: 4492

To resolve my problem, Just add this in webconfig.

<add assembly="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> 

and

<httpRuntime targetFramework="4.5" />

Upvotes: -1

MarkF
MarkF

Reputation: 962

To resolve this I had to add

<add assembly="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>

and

 <httpRuntime targetFramework="4.5.2" />

to the web.config

Upvotes: 11

Related Questions