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>
EL MOJO
  • 783
  • 1
  • 9
  • 22
  • 1
    Did you look at the configuration file from your other environments to make sure it includes the binding redirects? – mason May 17 '16 at 20:10
  • The error tells you all you need to know: some assembly in your application, either with or without a redirect in its config, still is linked to version 6. Look through "Main" (a branch in source control?), use Find in Files using an external editor, use Fusion logging to determine the calling assembly that requests version 6. The other way around, it could also be that some reference pulls in version 6 (because it wasn't updated to 8) and that version 6 ends up in your bin directory, causing your main assembly to fail to load its reference. – CodeCaster May 17 '16 at 20:13
  • Yes, and I've even done "Get-Project -All | Add-BindingRedirect" in the package manager console. I've wiped out everything and brought it back down, deleted the bin, done a clean, done a rebuild. – EL MOJO May 17 '16 at 20:14
  • @CodeCaster Yes I understand what the error means. I cannot find where it is still referencing the old version. Even if something is, why isn't the bindingRedirect in the web.config file doing its job? – EL MOJO May 17 '16 at 20:15
  • Well you only pasted half the error. The "manifest mismatch" one means that some assembly was linked against 6 and the runtime can only find 8 - and they're not exchangeable. – CodeCaster May 17 '16 at 20:17
  • I've used Fusion. All it tells me is that the DLL of my main project is the one calling for Newtonsoft.Json. That's the project that has the web.config file. The VS project file is pointing to version 8. – EL MOJO May 17 '16 at 20:18
  • Is it failing when loading the application or is it because of running tests? I am thinking may be your test project requires that dll now but it cannot find it in tests bin folder. – adeel41 May 17 '16 at 20:19
  • Please paste the full Fusion log in your question. I'm pretty sure that it finds version 6, while version 8 is requested. Through the redirect it will _try_ to use 6 as 8, but there's a mismatch and it errors. This will mean that some _other_ assembly pulls in version 6 during build. – CodeCaster May 17 '16 at 20:19
  • @adeel41 It is failing to load the application. – EL MOJO May 17 '16 at 20:20
  • It's finding 8 and expecting 6. This should be handled by the bindingRedirect. But still, no where is version 6 still referenced. – EL MOJO May 17 '16 at 20:24
  • Some other 3rd party dependency might be referencing Newtonsoft.Json version 6.0 but that is the whole reason Microsoft came up with the bindingRedirect mechanism. – EL MOJO May 17 '16 at 20:28
  • You're right that in the latter case, assembly redirection should solve the issue with dependencies referencing lower versions. But indeed in the line _"Post-policy reference: Newtonsoft.Json, Version=6.0.0.0"_ you can see that the assembly redirect is not applied. Are you sure this redirect is in the right position in the config, and that the config is in the right place? – CodeCaster May 17 '16 at 20:32
  • [link](http://stackoverflow.com/questions/21498074/how-can-i-fix-assembly-version-conflicts-with-json-net-after-updating-nuget-pack) refers to an a similar problem with an older Newtonsoft.Json update (ironically **to** version 6). – John Prideaux May 17 '16 at 20:32
  • If I could find where "Post-policy reference: Newtonsoft.Json, Version=6.0.0.0" is coming from I could fix the problem. Fusion doesn't tell me where that line is coming from. – EL MOJO May 17 '16 at 20:36
  • The bindingRedirect statement is within my web.config file which is actually referenced within the Fusion log. – EL MOJO May 17 '16 at 20:50
  • You can see in the _"Pre-bind state information === LOG: DisplayName = Newtonsoft.Json, Version=6.0.0.0"_ that the requesting assembly is linked to version 6 (you should also be able to see that by inspecting the assembly with ILDASM). This might mean your build system has version 6 cached somewhere. That the _"Post-policy reference"_ points to the same version, means (AFAIK) that the assembly redirect wasn't applied for some reason. Again, are you sure the redirect is in the right position in the configuration, namely under `configuration/runtime/assemblyBinding`? – CodeCaster May 17 '16 at 21:14
  • @CodeCaster Thanks for all the help by the way. Yes, the bindingRedirect is in configuration/runtime/assemblyBinding. – EL MOJO May 17 '16 at 21:17
  • Which assembly should I be inspecting with ILDASM? – EL MOJO May 17 '16 at 21:18
  • No problem, I've been bitten by this one before and it can be a persistent one. I'd love to see the outcome of this in your case, though it's probably going to be a "duh" moment. Anyway both this library and log4net have a history of it. You should inspect the assembly that is requestin version 6, which seems to be your web application's main assembly. – CodeCaster May 17 '16 at 21:19
  • The biggest question mark is why does my DEV work fine on my machine but my MAIN (which TFS says are identical) will not work on my machine. – EL MOJO May 17 '16 at 21:21

2 Answers2

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.

EL MOJO
  • 783
  • 1
  • 9
  • 22
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.

ciencia
  • 456
  • 4
  • 11