简体   繁体   English

在VS 2012项目中启用System.Net.Http

[英]Enabling System.Net.Http within VS 2012 Project

I'm fairly new to JSON development and just getting started is a major task with very little in the way of solutions via Google. 我对JSON开发还很陌生,刚刚入门是一项重要任务,只有很少的解决方案来自谷歌。

I can't get anywhere without adding system.net.http as part of my project 如果不在我的项目中添加system.net.http,我无法到达任何地方

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Net.Http;

objects like var, HttpWebClient, KeyValuePair throw up an error during compile. var,HttpWebClient,KeyValuePair等对象在编译期间抛出错误。 Here's what I tried: 这是我试过的:

  • Reinstalled .NET 4.0 重新安装.NET 4.0
  • Reinstalled .NET 4.5 重新安装.NET 4.5
  • Repackaged library via. 重新包装的库通过。 NuGet 的NuGet
  • Referenced system.net 引用的system.net

No luck. 没运气。 I've even tried referencing the the class in web.config 我甚至尝试在web.config中引用该类

<compilation targetFramework="4.5">
  <assemblies>
    <add assembly="System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </assemblies>
</compilation>

and again in.. 再次在..

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" />
      <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

An error is thrown on "assemblies" “程序集”上引发错误

I'm at my wits end. 我的智慧结束了。 What am I not referencing or doing wrong where System.Net.Http cannot be used. 在无法使用System.Net.Http的情况下,我没有引用或做错。

In .NET 4.5 System.Net.Http is in it's own assembly, you have to go to "Add References" (right click on the project) and select it. 在.NET 4.5中,System.Net.Http在它自己的程序集中,你必须转到“添加引用”(右键单击项目)并选择它。

See the MSDN page for HttpClient: http://msdn.microsoft.com/en-us/library/system.net.http.httpclient.aspx 请参阅HttpClient的MSDN页面: http//msdn.microsoft.com/en-us/library/system.net.http.httpclient.aspx

Assembly: System.Net.Http (in System.Net.Http.dll) 程序集:System.Net.Http(在System.Net.Http.dll中)

The help system reveals that the System.Net.Http namespace is defined in System.Net.Http.dll which as you say is not listed. 帮助系统显示System.Net.Http命名空间在System.Net.Http.dll中定义,如您所说,未列出。 A quick search of my own filesystem reveals copies 快速搜索我自己的文件系统会显示副本

  • In the GAC 在GAC中
  • In the framework folders for both 32 and 64 bit 在32和64位的框架文件夹中

On my system those paths are 在我的系统上,这些路径是

 C:\Windows\Microsoft.NET\Framework\v4.0.30319
 C:\Windows\Microsoft.NET\Framework64\v4.0.30319

System.Net.Http.WebRequest.dll is on the same paths. System.Net.Http.WebRequest.dll位于相同的路径上。

Did you try 你试过了吗

using System.Net.Http;

C# is a case-sensitive language. C#是一种区分大小写的语言。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM