问题
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.
回答1:
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
回答2:
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 :)
- Right-click the
References
folder >Add Reference...
- Expand Assemblies on the left side of the window and select Framework.
- Scroll to and select
System.Net.Http
in the list of assemblies. Make sure the box next toSystem.Net.Http
is checked, then clickOK
. - Rebuild the project.
回答3:
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" />
来源:https://stackoverflow.com/questions/26272743/system-net-http-missing