2012-12-21 62 views
3

我對JSON開發相當陌生,剛入門是一項非常重要的任務,很少有通過Google解決方案。在VS 2012項目中啓用System.Net.Http

我不能沒有增加system.net.http爲我的項目

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

對象,如VAR,HttpWebClient,KeyValuePair編譯期間拋出了一個錯誤的一部分取得任何進展。下面是我的嘗試:通過

  • 重新安裝.NET 4.0
  • 重新安裝.NET 4.5
  • 重新包裝庫。的NuGet
  • 引用system.net

沒有運氣。我甚至試過引用的類在web.config中

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

,並再次..

<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> 

將引發錯誤的「組件」

我在我的智慧結束。在System.Net.Http無法使用的情況下,我沒有引用或做錯。

回答

2

幫助系統顯示,System.Net.Http命名空間中System.Net.Http.dll就像你說的沒有列出其定義。快速搜索我自己的文件系統的揭示副本

  • 在GAC
  • 在框架文件夾爲32位和64位

在我的系統的路徑

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

System.Net.Http.WebRequest.dll是在相同的路徑。

+0

我可以拍我自己。習慣於直接輕鬆地引用該庫,我忘記直接映射它。像魅力一樣工作。然而HttpWebClient,FormURLEncodedContent,StreamReader和KeyValuePair(雖然是heirachy的一部分)拋出一個錯誤:「期望的類或...」 – Nanohurtz

0

你嘗試

using System.Net.Http; 

C#是區分大小寫的語言。

+0

哇,他們不是在用stackoverflow開玩笑的迴應時間..對不起,我離題了。是的,我加了..使用System.Net.Http;自動管理器沒有列出Http {}作爲選項,表明由於某種原因它沒有被加載 – Nanohurtz

4

在.NET 4.5 System.Net.Http是它自己的程序集,你必須去「添加引用」(右鍵單擊項目)並選擇它。

爲HttpClient的請參閱MSDN頁:http://msdn.microsoft.com/en-us/library/system.net.http.httpclient.aspx

Assembly: System.Net.Http (in System.Net.Http.dll)

+0

我打開了添加引用,並在.NET選項卡下添加了System.Net。添加引用表單並沒有提到它被篩選爲.NET Framework 4.這可能是一個問題嗎?我不確定System.Net.Http是否爲.NET 4.5庫。我檢查GAC_MSIL和system.net.http程序集確實存在。我想知道如何引用它。 – Nanohurtz

+0

確保您的項目設置爲.NET 4。5框架目標:http://msdn.microsoft.com/en-us/library/bb398202.aspx – mletterle

相關問題