![](/img/trans.png)
[英]Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies?
[英]Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies
首先,它不仅仅是重复。 以下问题的答案都不适用于我。
http://goo.gl/tS40cn
http://goo.gl/pH6v2T
我刚刚使用Nuget Package Manager更新了所有软件包,我开始收到此错误。
无法加载文件或程序集“Newtonsoft.Json,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = 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
为Newtonsoft.Json
删除dependentAssembly
配置 newVersion
到6.0.0.0
和7.0.0.0
中dependentAssembly
。 这样做会产生新的错误。 Get-Project -All | Add-BindingRedirect
Get-Project -All | Add-BindingRedirect
。 它改变了newVersion
的Newtonsoft.Json
到4.5.0.0
。 但问题仍未得到解决。 请帮我解决这个问题。
我知道这是旧的,但我遇到了同样的问题。 我的问题是解决方案中的多个项目使用了Newtonsoft.Json,但有些项目的版本不同。 我将所有这些更新到最新版本(我打字时为9.0.1),问题就消失了。
无论如何......如果有人还在处理这个问题,请确保在解决方案中的每个项目中更新包。
HTH
在我的MVC项目中添加Newtonsoft引用为我解决了这个问题。
在尝试了上述大部分内容(以及其他一些帖子)之后,我从包管理器中卸载了受影响项目的所有以下内容:
Microsoft.AspNet.WebApi
Microsoft.AspNet.Client
Microsoft.AspNet.Core
Microsoft.AspNet.WebHost
Newtonsoft.Json
然后重新安装了Microsoft.AspNet.WebApi,它自动安装了.Client,。Core,。WebHost,.Json。
运行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>
由于您在问题中说过您已尝试过此操作,因此您可能需要先尝试手动删除现有参考。 您可能还希望确保文件在磁盘上不是只读的,或者由源控件锁定。
我自己有这个错误,并且首先使用Update-Package –reinstall Newtonsoft.Json -IncludePrerelease
它不起作用,然后使用Install-Package Newtonsoft.Json
。 有效。
在包管理器控制台中运行此命令:
PM> Install-Package Newtonsoft.Json -Version 6.0.1
在我的例子中,以下代码存在于我的解决方案的本地调试版本中,但不存在于我的实时服务器版本的代码中。 将代码添加到我的服务器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>
将配置更改为如下所述:
检查项目参考中的'Newtonsoft.Json'版本。 在Web配置中添加该版本。 它会工作。 例如:您的Webconfig如下所示:
<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>
如果您在References中的版本是'9.0.0.0',请更改为:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json"publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="9.0.0.0"/>
</dependentAssembly>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.