Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 553
MarkF Avatar asked Sep 15 '25 08:09

MarkF


1 Answers

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

like image 131
MarkF Avatar answered Sep 17 '25 04:09

MarkF