我在我的一个名为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.