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

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

问题描述

这个错误让我发疯.

我在名为 BaseServices 的类库之一中安装了 SendGrid NuGet 包,它依赖于 Newtonsoft.Json v7.0.1,所以它会在我的包文件夹中安装它并引用它.

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 message) 中MyFolderBaseServicesEmailService.cs:line 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 MyFolderBaseServicesEmailService.cs:line 39

=== 预绑定状态信息 === LOG: DisplayName = Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed(完全指定)日志:Appbase = file:///MyFolder/Web/日志:初始PrivatePath = MyFolderWebin 调用程序集:SendGrid,版本=7.0.3.0,文化=中性,PublicKeyToken=4f047e93159395ca.=== LOG:此绑定在默认加载上下文中启动.日志:使用应用程序配置文件:MyFolderWebweb.config 日志:使用主机配置文件:C:UserscomputerDocumentsIISExpressconfigaspnet.config 日志:使用机器配置文件来自C:WindowsMicrosoft.NETFrameworkv4.0.30319configmachine.config.LOG:后政策参考:Newtonsoft.Json,版本=7.0.0.0,文化=中性,PublicKeyToken=30ad4fe6b2a6aeed 日志:正在尝试下载新网址file:///C:/Users/computer/AppData/Local/Temp/Temporary ASP.NET文件/root/ef9cacdf/e639667a/Newtonsoft.Json.DLL.日志:尝试下载新网址file:///C:/Users/computer/AppData/Local/Temp/Temporary ASP.NET文件/root/ef9cacdf/e639667a/Newtonsoft.Json/Newtonsoft.Json.DLL.日志:正在尝试下载新 URLfile:///MyFolder/Web/bin/Newtonsoft.Json.DLL.警告:比较程序集名称导致不匹配:Major Version ERR: Failed to组装完成(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 = MyFolderWebin 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: MyFolderWebweb.config LOG: Using host configuration file: C:UserscomputerDocumentsIISExpressconfigaspnet.config LOG: Using machine configuration file from C:WindowsMicrosoft.NETFrameworkv4.0.30319configmachine.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, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed"或其依赖项之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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