[英]Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies
First, It is not just duplicate. 首先,它不仅仅是重复。 None of answers from following questions are working for me.
以下问题的答案都不适用于我。
http://goo.gl/tS40cn http://goo.gl/tS40cn
http://goo.gl/pH6v2T http://goo.gl/pH6v2T
I've just updated all my packages using Nuget Package Manager and I started receiving this error. 我刚刚使用Nuget Package Manager更新了所有软件包,我开始收到此错误。
Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. 无法加载文件或程序集“Newtonsoft.Json,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = 30ad4fe6b2a6aeed”或其中一个依赖项。 The located assembly's manifest definition does not match the assembly reference.
定位的程序集的清单定义与程序集引用不匹配。 (Exception from HRESULT: 0x80131040)
(HRESULT异常:0x80131040)
My Package Config has: 我的包裹配置有:
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
Web.config includes this piece of code: 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>
Properties from Reference for Newtonsoft.Json
参考资料来自
Newtonsoft.Json
According to the answers from the similar questions, I have tried followings: 根据类似问题的答案,我尝试了以下方法:
Update-Package –reinstall Newtonsoft.Json
Update-Package –reinstall Newtonsoft.Json
重新安装软件包 dependentAssembly
config from Web.config
for Newtonsoft.Json
Web.config
为Newtonsoft.Json
删除dependentAssembly
配置 newVersion
to 6.0.0.0
and 7.0.0.0
in dependentAssembly
. newVersion
到6.0.0.0
和7.0.0.0
中dependentAssembly
。 Doing so gave birth to new error. Get-Project -All | Add-BindingRedirect
Get-Project -All | Add-BindingRedirect
Get-Project -All | Add-BindingRedirect
. Get-Project -All | Add-BindingRedirect
。 It changes newVersion
for Newtonsoft.Json
to 4.5.0.0
. newVersion
的Newtonsoft.Json
到4.5.0.0
。 But issue remains unresolved. Please help me fixing this. 请帮我解决这个问题。
I know this is old, but I just ran into the same problem. 我知道这是旧的,但我遇到了同样的问题。 My issue was that multiple projects in the solution used Newtonsoft.Json, but some were at different versions.
我的问题是解决方案中的多个项目使用了Newtonsoft.Json,但有些项目的版本不同。 I updated all of them to the most recent (9.0.1 as I type) and the problem went away.
我将所有这些更新到最新版本(我打字时为9.0.1),问题就消失了。
Anyway... if anyone is still dealing with this, make sure to update the package in EVERY project in the solution. 无论如何......如果有人还在处理这个问题,请确保在解决方案中的每个项目中更新包。
HTH HTH
在我的MVC项目中添加Newtonsoft引用为我解决了这个问题。
After trying much of the above (and some other posts), I uninstalled with the package manager all of the following from the project affected: 在尝试了上述大部分内容(以及其他一些帖子)之后,我从包管理器中卸载了受影响项目的所有以下内容:
Microsoft.AspNet.WebApi
Microsoft.AspNet.Client
Microsoft.AspNet.Core
Microsoft.AspNet.WebHost
Newtonsoft.Json
Then reinstalled Microsoft.AspNet.WebApi, which auto installed .Client, .Core, .WebHost, .Json. 然后重新安装了Microsoft.AspNet.WebApi,它自动安装了.Client,。Core,。WebHost,.Json。
Run Update-Package Newtonsoft.Json -Reinstall
运行
Update-Package Newtonsoft.Json -Reinstall
It should remove the reference to your 4.5 version, and reinstall the newer version referenced in your package.config. 它应该删除对4.5版本的引用,并重新安装package.config中引用的较新版本。 It will also update the binding redirect, which should then be as follows:
它还将更新绑定重定向,然后应如下所示:
<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>
Since you said in your question that you already tried this, you might want to first try removing the existing reference manually. 由于您在问题中说过您已尝试过此操作,因此您可能需要先尝试手动删除现有参考。 You might also want to make sure the files aren't read-only on disk, or otherwise locked by source control.
您可能还希望确保文件在磁盘上不是只读的,或者由源控件锁定。
I had this error myself, and first used Update-Package –reinstall Newtonsoft.Json -IncludePrerelease
it didn't work, then used Install-Package Newtonsoft.Json
. 我自己有这个错误,并且首先使用
Update-Package –reinstall Newtonsoft.Json -IncludePrerelease
它不起作用,然后使用Install-Package Newtonsoft.Json
。 it worked. 有效。
在包管理器控制台中运行此命令:
PM> Install-Package Newtonsoft.Json -Version 6.0.1
In my case, the following code was present in my local debug version of the solution, but not in my live server version of code. 在我的例子中,以下代码存在于我的解决方案的本地调试版本中,但不存在于我的实时服务器版本的代码中。 Adding the code to my server Web.config file fixed the problem.
将代码添加到我的服务器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>
将配置更改为如下所述:
check the 'Newtonsoft.Json' version in the project references. 检查项目参考中的'Newtonsoft.Json'版本。 Add that version in the Web config.
在Web配置中添加该版本。 It will work.
它会工作。 For Example: your Webconfig look like this:
例如:您的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>
If your version in References is '9.0.0.0' change to this: 如果您在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.