問題描述
我收到錯誤消息
System.IO.FileLoadException:無法加載文件或程序集'Newtonsoft.Json,版本=4.5.0.0,文化=中性,PublicKeyToken=30ad4fe6b2a6aeed' 或其依賴項之一.這定位程序集的清單定義與程序集不匹配參考.(HRESULT 異常:0x80131040)
System.IO.FileLoadException : Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
對于我的 CI 構建
我嘗試過的解決方案
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
它也沒有工作
推薦答案
在包管理器控制臺執行:Update-Package –reinstall Newtonsoft.Json
.
In package manager console execute: Update-Package –reinstall Newtonsoft.Json
.
更新
我最初將此作為評論發布,但正如 @OwenBlacker 建議的那樣,我將其放在這里:
如果您在執行此操作后仍然遇到錯誤,那么最終對我有用的是我從 .config
文件中刪除了 Json.Net 的 <dependentAssembly>
部分.如果它不存在,則重新安裝會將其恢復,顯然您需要將其刪除.直到包本身有正常的解決方案,恐怕這個手動步驟是必須的.
If you still get an error after doing this, then what worked for me eventually is that I deleted Json.Net's <dependentAssembly>
section from my .config
file. Reinstall brings it back if it's not there and apparently you need to delete it. Until there will be a normal solution in the package itself, I'm afraid this manual step is a must.
注意:請在執行此操作之前閱讀以下評論.
根據 René 在 BE AWARE 下面的評論,答案中發布的命令將在您的解決方案中的每個項目中重新安裝包.因此,如果您在多個項目中使用 Newtonsoft.Json 包并且可能使用不同的版本,則僅執行上述命令可能會產生不良后果.
As per René's comment below BE AWARE that the command posted in the answer will reinstall the package in every project in your solution. So if you use the Newtonsoft.Json package in several projects and maybe use different versions, just executing the above command might have unwanted consequences.
這篇關于無法加載文件或程序集“Newtonsoft.Json,版本=4.5.0.0,文化=中性,PublicKeyToken=30ad4fe6b2a6aeed"的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!