0
votes

Using Visual Studio 2013 Pro:

Here is a little conundrum I have with a web site project (NOT application) that makes use of a NuGet package:

Package A depends on the package Newtonsoft.Json

I install Package A and it in turn installs its dependency: Newtonsoft.Json version 6.0.0

I test my web pages and everything works fine …

In Visual Studio, I do the following:

Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution …

I click on “Updates” and the package manager display an update is available for Newtonsoft.Json (to version 8.0.2)

Naturally, wanting the latest and greatest, I click “Update”

Newtonsoft.Json is downloaded and updated to version 8.0.2

I test my web pages again and behold …

EXCEPTION: System.IO.FileLoadException: 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. (Exception from HRESULT: 0x80131040) File name: 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'

So my question is: How to resolve this?…

The only way I been able to is to (so far), is to remove all packages and re-install Package A again as it demands version 6.0.0 of Newtonsoft.Json

BUT, what if I make use of another NuGet package (lets say, Package B) that had a dependency on a different version of Newtonsoft.Json ? In other words, if I make use of any other NuGet package with the same dependency but a different version, an exception will eventually be raised by those pages making use of a package on which a specific dependency version does not exist?

Is there any way around such a scenario – or if I have more than one package that depend on Newtonsoft.Json -- will all packages have to rely on the same version?

Hope I made this clear enough, thanks in advance.

2

2 Answers

0
votes

In the case that the update is backwards compatible you can use a BindingRedirect:

<dependentAssembly>
    <assemblyIdentity name="someAssembly" publicKeyToken="32ab4ba45e0a69a1" culture="en-us" />
    <bindingRedirect oldVersion="6.0.0.0" newVersion="8.0.2.0" />
  </dependentAssembly>

This obviously only works for backwards compatible upgrades, if the API changes, you're in trouble. More information on BindingRedirects can be found here:

https://msdn.microsoft.com/en-us/library/7wd6ex19(v=vs.110).aspx

0
votes

This is a common issue, like Kenneth says if it supports backward compatibility it should work with "bindingRedirect".

"The only way I been able to is to (so far), is to remove all packages and re-install Package..."

For the question to update Nuget without removing the dlls, you can install the specific version of the Nuget.

VS -> Tools -> Nuget Package Manager -> Package Manager Console and run the following command,

Install-Package Newtonsoft.Json -Version 6.0.1

You can see the history of Newtonsoft versions in this page and select the required one.

This will downgrade/upgrade the existing package.