.net – 无法加载文件或程序集’Newtonsoft.Json,Version = 7.0.0.0,Culture = neutral,PublicKeyToken = 30ad4fe6b2a6aeed’或其依赖项之一

前端之家收集整理的这篇文章主要介绍了.net – 无法加载文件或程序集’Newtonsoft.Json,Version = 7.0.0.0,Culture = neutral,PublicKeyToken = 30ad4fe6b2a6aeed’或其依赖项之一前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这一个错误让我疯了.

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

在类库中,我有这个绑定重定向

<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库的v6,如下所示:

<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库中的代码时,我收到此错误

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,
PublicKeyToken=30ad4fe6b2a6aeed’ at
SendGrid.Helpers.Mail.Mail.Get() at
BaseServices.EmailService.SendAsync(EmailMessage message) in
MyFolder\BaseServices\EmailService.cs:line 39

=== Pre-bind state information === LOG: DisplayName = Newtonsoft.Json,PublicKeyToken=30ad4fe6b2a6aeed
(Fully-specified) LOG: Appbase = file:///MyFolder/Web/ LOG: Initial
PrivatePath = MyFolder\Web\bin Calling assembly : SendGrid,
Version=7.0.3.0,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,
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库.要解决此问题,您应该将它们升级到最新版本.跟着这些步骤:

>开放式解决方
>右键单击解决方名称
>选择管理解决方案的Nuget包
>从菜单中选择更新
>更新JSON.NET包

这将解决您的问题.

原文链接:/json/729721.html

猜你在找的Json相关文章