简体   繁体   English

无法加载文件或程序集“Newtonsoft.Json”或其依赖项之一

[英]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: 根据类似问题的答案,我尝试了以下方法:

  • Reinstalling package using Update-Package –reinstall Newtonsoft.Json 使用Update-Package –reinstall Newtonsoft.Json重新安装软件包
  • Removing dependentAssembly config from Web.config for Newtonsoft.Json Web.configNewtonsoft.Json删除dependentAssembly配置
  • Changing newVersion to 6.0.0.0 and 7.0.0.0 in dependentAssembly . 更改newVersion6.0.0.07.0.0.0dependentAssembly Doing so gave birth to new error. 这样做会产生新的错误。
  • Also tried 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 . 它改变了newVersionNewtonsoft.Json4.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
  1. In your VS solution explorer, remove the Newtonsoft.Json reference. 在VS解决方案资源管理器中,删除Newtonsoft.Json引用。
  2. Download the 6.0 binary files at Newtonsoft binary files here 此处下载Newtonsoft二进制文件中的6.0二进制文件
  3. Extract the files 提取文件
  4. Add the Newtonsoft library manually. 手动添加Newtonsoft库。 From Visual Studio, right click Reference and select Add Reference 在Visual Studio中,右键单击“引用”并选择“添加引用”
  5. Click Browse 单击“浏览”
  6. Navigate to the extracted files under Net45 and select Newtonsoft.Json.dll 导航到Net45下的解压缩文件,然后选择Newtonsoft.Json.dll
  7. If it does not work try using Net40 instead by going through the whole procedure again. 如果它不起作用,请尝试使用Net40,而不是再次完成整个过程。

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.

相关问题 无法加载文件或程序集“ Newtonsoft.Json”或其依赖项之一? - Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies? 无法加载文件或程序集“ Newtonsoft.Json”或其依赖项之一。 清单定义与程序集引用不匹配。 - Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies. manifest definition does not match the assembly reference. 无法加载文件或程序集“ Newtonsoft.Json” - Could not load file or assembly 'Newtonsoft.Json' 无法加载文件或程序集“newtonsoft.json” - could not load file or assembly 'newtonsoft.json' 无法加载文件或程序集“Newtonsoft.Json,Version=9.0.0.0,Culture=neutral,PublicKeyToken=30ad4fe6b2a6aeed”或其依赖项之一 - Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies 例:无法加载文件或程序集“ Newtonsoft.Json,版本= 6.0.0.0,文化=中性,PublicKeyToken = 30ad4fe6b2a6aeed”或其依赖项之一 - Exc.: 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=12.0.0.0,Culture=neutral,PublicKeyToken=30ad4fe6b2a6aeed”或其依赖项之一 - Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies 无法加载文件或程序集Newtonsoft.json版本6.0.0.0 - Could not load file or assembly Newtonsoft.json Version 6.0.0.0 无法在特定计算机上加载文件或程序集“ Newtonsoft.Json” - Could not load file or assembly 'Newtonsoft.Json' on specific machine Newtonsoft.Json版本8.0.2无法加载文件或程序集错误 - Newtonsoft.Json version 8.0.2 Could not load file or assembly Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM