This one error is driving me nuts.
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>
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>
When I run my email sending code that is in the BaseServices library, I get this error:
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
=== 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.
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:
This will resolve your issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With