Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load file or assembly 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies

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.

like image 847
Water Cooler v2 Avatar asked Jul 05 '16 11:07

Water Cooler v2


1 Answers

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. Open solution explorer
  2. Right Click on solution name
  3. Select Manage Nuget Packages for Solution
  4. Select Updates from menu
  5. Update JSON.NET package

This will resolve your issue.

like image 69
Mahendra Avatar answered Nov 15 '22 02:11

Mahendra