问题描述
我收到错误消息
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"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!