无法加载文件或程序集"Newtonsoft.Json,版本= 7.0.0.0,区域性=中性,PublicKeyToken = 30ad4fe6b2a6aeed"或其依赖项之一 [英] Could not load file or assembly 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies

查看:142
本文介绍了无法加载文件或程序集"Newtonsoft.Json,版本= 7.0.0.0,区域性=中性,PublicKeyToken = 30ad4fe6b2a6aeed"或其依赖项之一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个错误使我发疯.

我在名为 BaseServices 的一个类库中安装了 SendGrid NuGet软件包,该软件包依赖于 Newtonsoft.Json v7.0.1 ,因此它将其安装在我的packages文件夹中并对其进行引用.

I installed the SendGrid NuGet package in one of my class libraries named BaseServices, which has a dependency on Newtonsoft.Json v7.0.1, so it installs that in my packages folder and references that.

在类库中,我具有此绑定重定向:

In the class library, I have this binding redirect:

<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>

在ASP.NET MVC应用程序(即使用我的类库的客户端应用程序)的web.config中,对于小于v6的版本,我具有程序集绑定重定向,以指向 Newtonsoft.Json 库如下:

In the web.config of the ASP.NET MVC application, i.e. the client application that uses my class library, I have an assembly binding redirect for versions less than v6 to point to v6 of the Newtonsoft.Json library like so:

<dependentAssembly>
 <assemblyIdentity name="Newtonsoft.Json" culture="neutral"
              publicKeyToken="30ad4fe6b2a6aeed" />
  <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>

运行 BaseServices 库中的电子邮件发送代码时,出现以下错误:

When I run my email sending code that is in the BaseServices library, I get this error:

线程0x1a4c已退出,代码为0(0x0). System.IO.FileLoadException:无法加载文件或程序集 'Newtonsoft.Json,版本= 7.0.0.0,文化=中性, PublicKeyToken = 30ad4fe6b2a6aeed"或其依赖项之一.这 定位的程序集的清单定义与程序集不匹配 参考. (来自HRESULT的异常:0x80131040)文件名: 'Newtonsoft.Json,版本= 7.0.0.0,文化=中性, PublicKeyToken = 30ad4fe6b2a6aeed" 的SendGrid.Helpers.Mail.Mail.Get() 中的BaseServices.EmailService.SendAsync(EmailMessage消息) MyFolder \ BaseServices \ EmailService.cs:第39行

The thread 0x1a4c has exited with code 0 (0x0). System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=7.0.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) File name: 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' at SendGrid.Helpers.Mail.Mail.Get() at BaseServices.EmailService.SendAsync(EmailMessage message) in MyFolder\BaseServices\EmailService.cs:line 39

===预绑定状态信息===日志:DisplayName = Newtonsoft.Json,版本= 7.0.0.0,区域性=中性,PublicKeyToken = 30ad4fe6b2a6aeed (完全指定)LOG:Appbase = file:///MyFolder/Web/LOG:初始 PrivatePath = MyFolder \ Web \ bin调用程序集:SendGrid, 版本= 7.0.3.0,区域性=中性,PublicKeyToken = 4f047e93159395ca. === LOG:此绑定在默认的加载上下文中启动.日志:使用应用程序配置文件:MyFolder \ Web \ web.config日志:使用 主机配置文件: C:\ Users \ computer \ Documents \ IISExpress \ config \ aspnet.config日志:使用 机器配置文件来自 C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ config \ machine.config. 日志:政策后参考:Newtonsoft.Json,版本= 7.0.0.0, 文化=中性,PublicKeyToken = 30ad4fe6b2a6aeed日志:尝试 下载新网址 文件:///C:/Users/computer/AppData/Local/Temp/Temporary ASP.NET 文件/root/ef9cacdf/e639667a/Newtonsoft.Json.DLL.日志:尝试 下载新网址 文件:///C:/Users/computer/AppData/Local/Temp/Temporary ASP.NET 文件/root/ef9cacdf/e639667a/Newtonsoft.Json/Newtonsoft.Json.DLL.日志: 尝试下载新的URL 文件:///MyFolder/Web/bin/Newtonsoft.Json.DLL. WRN:比较 程序集名称导致不匹配:主要版本ERR:失败 完成组装的设置(hr = 0x80131040).探测终止.

=== Pre-bind state information === LOG: DisplayName = Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed (Fully-specified) LOG: Appbase = file:///MyFolder/Web/ LOG: Initial PrivatePath = MyFolder\Web\bin Calling assembly : SendGrid, Version=7.0.3.0, Culture=neutral, PublicKeyToken=4f047e93159395ca. === LOG: This bind starts in default load context. LOG: Using application configuration file: MyFolder\Web\web.config LOG: Using host configuration file: C:\Users\computer\Documents\IISExpress\config\aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Post-policy reference: Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed LOG: Attempting download of new URL file:///C:/Users/computer/AppData/Local/Temp/Temporary ASP.NET Files/root/ef9cacdf/e639667a/Newtonsoft.Json.DLL. LOG: Attempting download of new URL file:///C:/Users/computer/AppData/Local/Temp/Temporary ASP.NET Files/root/ef9cacdf/e639667a/Newtonsoft.Json/Newtonsoft.Json.DLL. LOG: Attempting download of new URL file:///MyFolder/Web/bin/Newtonsoft.Json.DLL. WRN: Comparing the assembly name resulted in the mismatch: Major Version ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

推荐答案

您的解决方案中有2个不同版本的JSON.NET库.为了解决这个问题,您应该将它们升级到最新版本.请按照下列步骤操作:

You have 2 different versions of JSON.NET library in your solution. To solve this you should upgrade them to latest version. Follow these steps:

  1. 打开解决方案资源管理器
  2. 右键单击解决方案名称
  3. 选择管理解决方案的Nuget程序包
  4. 从菜单中选择更新
  5. 更新JSON.NET包

这将解决您的问题.

这篇关于无法加载文件或程序集"Newtonsoft.Json,版本= 7.0.0.0,区域性=中性,PublicKeyToken = 30ad4fe6b2a6aeed"或其依赖项之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆