2015-09-27 85 views
6

一是之一,它不僅是重複的。以下問題的答案都不適用於我。無法加載文件或程序集「Newtonsoft.Json」或一個依賴

http://goo.gl/tS40cn
http://goo.gl/pH6v2T

我剛剛更新使用NuGet包管理器中所有我的包,我開始收到此錯誤。

無法加載文件或程序集「Newtonsoft.Json,版本= 6.0.0.0,文化=中性公鑰= 30ad4fe6b2a6aeed」或它的一個依賴。定位的程序集清單定義與程序集引用不匹配。 (從HRESULT異常:0x80131040)

我的包配置有:

<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" /> 

Web.config中包括這一段代碼:從參考

<dependentAssembly> 
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> 
    <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" /> 
    </dependentAssembly> 

屬性Newtonsoft.Json

enter image description here

據來自類似的問題的答案,我已經試過如下:

  • 重新安裝使用Update-Package –reinstall Newtonsoft.Json
  • 去除Web.configdependentAssembly配置包Newtonsoft.Json
  • dependentAssembly更改newVersion6.0.0.07.0.0.0。這樣做產生了新的錯誤。
  • 也試過Get-Project -All | Add-BindingRedirect。它改變了newVersionNewtonsoft.Json4.5.0.0。但問題仍未解決。

請幫我解決這個。

+3

你有沒有建立之前乾淨生成文件夾的內容?你的目標是與引用的dll相同的框架版本嗎? – ilansch

回答

0

運行此命令在包管理器控制檯:

PM> Install-Package Newtonsoft.Json -Version 6.0.1 
+0

沒有工作。出現錯誤'Install-Package:將'Newtonsoft.Json 7.0.1'更新爲'Newtonsoft.Json 6.0.1'失敗。無法找到兼容 'Newtonsoft.Json 6.0.1'的'Microsoft.AspNet.WebApi.Client'版本 – shashwat

0
  1. 在你的VS解決方案資源管理器,刪除Newtonsoft.Json參考。
  2. 下載6.0二進制文件在Newtonsoft二進制文件here
  3. 將文件解壓
  4. 手動添加Newtonsoft庫。從Visual Studio中,右鍵單擊參考,並選擇Add Reference
  5. 點擊瀏覽
  6. 導航到Net45下提取的文件,並選擇Newtonsoft.Json.dll
  7. 如果它不能正常工作的,而不是通過整體去嘗試使用Net40程序再次。
0

運行Update-Package Newtonsoft.Json -Reinstall

應該刪除引用到你的4.5版本,並重新安裝在您的package.config引用的新版本。它也將更新綁定重定向,那麼這應該是如下:由於你在你的問題,你已經嘗試過此說

<dependentAssembly> 
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> 
    <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" /> 
</dependentAssembly> 

,你可以嘗試手動刪除現有的參考要第一。您可能還想確保這些文件在磁盤上不是隻讀的,或者被源代碼控制鎖定。

+0

謝謝!我記得,我已經嘗試過了。但很快就會再試一次並在此更新 – shashwat

+0

對於遲到的回覆很抱歉。按照您的建議運行命令後,我仍然收到相同的錯誤。它將綁定重定向設置爲''。我試着改變你給的'''。但它產生了這個錯誤'無法加載文件或程序集'Newtonsoft.Json'或它的一個依賴項。定位的程序集清單定義與程序集引用不匹配。 (來自HRESULT的異常:0x80131040)'。 – shashwat

0

就我而言,以下代碼出現在本地調試版本的解決方案中,但未出現在我的實時服務器版本的代碼中。將代碼添加到我的服務器Web.config文件中解決了問題。

<runtime> 
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
    <dependentAssembly> 
    <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" /> 
    <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" /> 
    </dependentAssembly> 
    <dependentAssembly> 
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" /> 
    <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" /> 
    </dependentAssembly> 
</assemblyBinding> 

0

我有這個錯誤我自己,第一次使用Update-Package –reinstall Newtonsoft.Json -IncludePrerelease它沒有工作,然後使用Install-Package Newtonsoft.Json。有效。

1

在我的MVC項目中添加Newtonsoft引用爲我解決了這個問題。

6

我知道這是舊的,但我碰到了同樣的問題。我的問題是解決方案中的多個項目使用了Newtonsoft.Json,但有一些版本不同。我將它們全部更新到最新的版本(我輸入時爲9.0.1),問題就消失了。

無論如何...如果有人仍在處理此問題,請務必在解決方案中的每個項目中更新軟件包。

HTH

1

想太多以上(和一些其他職位)之後,我使用包管理器卸載以下所有的受影響的項目:

Microsoft.AspNet.WebApi 
Microsoft.AspNet.Client 
Microsoft.AspNet.Core 
Microsoft.AspNet.WebHost 
Newtonsoft.Json 

然後重新安裝Microsoft.AspNet。 WebApi,它自動安裝.Client,.Core,.WebHost,.Json。

0

更改配置如下提到:

+0

相關問題