Newtonsoft.Json Assembly Conflict - DLL Hell

1

Trying to upgrade to Newtonsoft.Json version 8 and I keep getting "Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0. Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference."

Nowhere does my project (or any project within my solution) reference version 6 anymore. I've scoured the internet and stack exchange but none of the suggestions have worked. I have this listed in my web.config file:

<dependentAssembly>
  <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
</dependentAssembly>

The project loads fine in my local environment. After I push to Main and deploy it to QA, it bombs in QA. I pull Main down to my local machine and it crashes with the same error.

I'm totally frustrated. If you have any suggestions other than what has already been mentioned all over the internet, I'd be glad to hear it.

I've tried Fusion (wasn't helpful).

EDIT:

Fusion Error log

*** Assembly Binder Log Entry  (5/17/2016 @ 1:48:49 PM) ***

The operation failed.
Bind result: hr = 0x80131040. No description available.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\WINDOWS\SysWOW64\inetsrv\w3wp.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
 (Fully-specified)
LOG: Appbase = file:///C:/Development/MyApp/Main/Services/MyAppInternal/MY.MyApp.Services.REST/
LOG: Initial PrivatePath = C:\Development\MyApp\Main\Services\MyAppInternal\MY.MyApp.Services.REST\bin
LOG: Dynamic Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\68a38e3a
LOG: Cache Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\68a38e3a
LOG: AppName = fd029416
Calling assembly : MY.MyApp.Services.REST, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Development\MyApp\Main\Services\MyAppInternal\MY.MyApp.Services.REST\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\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=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/68a38e3a/fd029416/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/68a38e3a/fd029416/Newtonsoft.Json/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Development/MyApp/Main/Services/MyAppInternal/MY.MyApp.Services.REST/bin/Newtonsoft.Json.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Development\MyApp\Main\Services\MyAppInternal\MY.MyApp.Services.REST\bin\Newtonsoft.Json.dll
LOG: Entering download cache setup phase.
LOG: Assembly Name is: Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: The assembly reference did not match the assembly definition found.
ERR: Setup failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

*** Assembly Binder Log Entry  (5/17/2016 @ 1:48:49 PM) ***

The operation failed.
Bind result: hr = 0x80131040. No description available.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\WINDOWS\SysWOW64\inetsrv\w3wp.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
 (Fully-specified)
LOG: Appbase = file:///C:/Development/MyApp/Main/Services/MyAppInternal/MY.MyApp.Services.REST/
LOG: Initial PrivatePath = C:\Development\MyApp\Main\Services\MyAppInternal\MY.MyApp.Services.REST\bin
LOG: Dynamic Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\68a38e3a
LOG: Cache Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\68a38e3a
LOG: AppName = fd029416
Calling assembly : MY.MyApp.Services.REST, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Development\MyApp\Main\Services\MyAppInternal\MY.MyApp.Services.REST\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\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=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/68a38e3a/fd029416/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/68a38e3a/fd029416/Newtonsoft.Json/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Development/MyApp/Main/Services/MyAppInternal/MY.MyApp.Services.REST/bin/Newtonsoft.Json.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Development\MyApp\Main\Services\MyAppInternal\MY.MyApp.Services.REST\bin\Newtonsoft.Json.dll
LOG: Entering download cache setup phase.
LOG: Assembly Name is: Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: The assembly reference did not match the assembly definition found.
ERR: Setup failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

EDIT:

I went through every project file in my solution and they all reference Newtonsoft.Json the following way:

<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
  <HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
  <Private>True</Private>
</Reference>
asp.net
json.net
asked on Stack Overflow May 17, 2016 by EL MOJO • edited May 17, 2016 by EL MOJO

2 Answers

0

Well, not the answer I was looking for but it solved my problem. I rolled Newtonsoft.Json back to version 6. This got rid of the runtime error. I really couldn't afford to waste more time troubleshooting a problem that shouldn't have been a problem.

While doing all of my troubleshooting, i found that many of my 3rd party dependencies rely on Newtonsoft.Json (in various different versions). WebApi 2.2 needs version 6. Some others want version 5.

This mix of version requirements was the whole reason bindingRedirect was created. So my issue really is with bindingRedirect not working as designed.

answered on Stack Overflow May 18, 2016 by EL MOJO
0

I had the same problem: Everything works on development, and I get this error when deploying to the prepro/production server. My web.config already had the bindingRedirect.

It was resolved magically after updating all packages to the latest version in NuGet and redeploying again. Apparently, it was using the packages with the versions that shipped with VisualStudio, and updating them solved the issue somehow.

answered on Stack Overflow Oct 3, 2018 by ciencia

User contributions licensed under CC BY-SA 3.0