无法加载文件或程序集“Newtonsoft.Json”或一个依赖
一是之一,它不仅是重复的。以下问题的答案都不适用于我。无法加载文件或程序集“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
据来自类似的问题的答案,我已经试过如下:
- 重新安装使用
Update-Package –reinstall Newtonsoft.Json
- 去除
Web.config
dependentAssembly
配置包Newtonsoft.Json
- 在
dependentAssembly
更改newVersion
到6.0.0.0
和7.0.0.0
。这样做产生了新的错误。 - 也试过
Get-Project -All | Add-BindingRedirect
。它改变了newVersion
向Newtonsoft.Json
4.5.0.0
。但问题仍未解决。
请帮我解决这个。
运行此命令在包管理器控制台:
PM> Install-Package Newtonsoft.Json -Version 6.0.1
没有工作。出现错误'Install-Package:将'Newtonsoft.Json 7.0.1'更新为'Newtonsoft.Json 6.0.1'失败。无法找到兼容 'Newtonsoft.Json 6.0.1'的'Microsoft.AspNet.WebApi.Client'版本 – shashwat
- 在你的VS解决方案资源管理器,删除Newtonsoft.Json参考。
- 下载6.0二进制文件在Newtonsoft二进制文件here
- 将文件解压
- 手动添加Newtonsoft库。从Visual Studio中,右键单击参考,并选择Add Reference
- 点击浏览
- 导航到Net45下提取的文件,并选择Newtonsoft.Json.dll
- 如果它不能正常工作的,而不是通过整体去尝试使用Net40程序再次。
运行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>
,你可以尝试手动删除现有的参考要第一。您可能还想确保这些文件在磁盘上不是只读的,或者被源代码控制锁定。
就我而言,以下代码出现在本地调试版本的解决方案中,但未出现在我的实时服务器版本的代码中。将代码添加到我的服务器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>
我有这个错误我自己,第一次使用Update-Package –reinstall Newtonsoft.Json -IncludePrerelease
它没有工作,然后使用Install-Package Newtonsoft.Json
。有效。
在我的MVC项目中添加Newtonsoft引用为我解决了这个问题。
我知道这是旧的,但我碰到了同样的问题。我的问题是解决方案中的多个项目使用了Newtonsoft.Json,但有一些版本不同。我将它们全部更新到最新的版本(我输入时为9.0.1),问题就消失了。
无论如何...如果有人仍在处理此问题,请务必在解决方案中的每个项目中更新软件包。
HTH
想太多以上(和一些其他职位)之后,我使用包管理器卸载以下所有的受影响的项目:
Microsoft.AspNet.WebApi
Microsoft.AspNet.Client
Microsoft.AspNet.Core
Microsoft.AspNet.WebHost
Newtonsoft.Json
然后重新安装Microsoft.AspNet。 WebApi,它自动安装.Client,.Core,.WebHost,.Json。
更改配置如下提到:
你有没有建立之前干净生成文件夹的内容?你的目标是与引用的dll相同的框架版本吗? – ilansch