0

I’ve a solution with somewhere in the region of 60 projects, most of which use Newtonsoft.Json.dll and many of which reference each other. Things were building nicely, no warnings.

Took a look at the Consolidate feature of the nugget package manager, and it seemed to be quite useful- multiple projects using different versions of Newtonsoft could be quickly regularised to all use the same version. Most projects use the same version, some were ahead by a few minors, some lagged by at most one major version. Click click done, all projects now have the same version installed and referenced. Apparently.

Warnings appear about finding different conflicting versions of the same assembly, so I decided to file-find every Newtonsoft.Json.dll under the project tree and erase them, and also erase the solutiondir\packages\Newtonsoft.Json folder, then do a package restore and a rebuild the solution..

Bizarrely, it doesn’t seem to have helped.. I genuinely thought that clearing the old versions and having had NPM make every project in the solution on the same version, would mean there weren’t 9 different versions of it kicking around, but sure enough doing a search for the dll turns up different sized files all over the solution tree

What’s the right way to handle this and kill off the warnings about conflicting assemblies post consolidate?

Caius Jard
  • 72,509
  • 5
  • 49
  • 80
  • If any of your project dependencies *also* have a dependency on Newtonsoft, they'll pull in their own versions. Consolidate only affects your projects, not their dependencies. I assume that's what is happening. –  Nov 20 '18 at 20:35
  • Maybe your projects depend on nuget packages which depend on older versions of Newtonsoft.Json? – Andrzej Gis Nov 20 '18 at 21:01
  • It’s slightly confusing to me how there are now more warnings than there were before, about conflicting versions.. could it really be the case that the previous mishmash was so accurately balanced in terms of my projects that depend on other projects that depend on Newtonsoft, that both my projects and the other projects all depended on the same (different) versions? – Caius Jard Nov 20 '18 at 21:24
  • And does it mean that there is ultimately no solution other than whacking binding redirects in all over the place? – Caius Jard Nov 20 '18 at 21:28
  • If you have a direct dependency on `A-1.2.3`, and one of your dependencies has a dependency on `A-1.2.0`, you will need to use binding redirects, because consolidate will do nothing here. You only need assembly redirects in executable (or website) configuration files. Libraries don't need them, so "all over the place", no. –  Nov 20 '18 at 22:02

1 Answers1

0

I was able to resolve the warnings for my context, after realising that many of the projects in the solution had a web config binding redirect that called for 0.0.0.0-6.0.0.0 of Newtonsoft.Json to be redirected to 6.0.0.0

The installed version (5.0.2) had an assembly version of 4.5.0.0, the first one that I could find that had an assemblyversion of 6.0.0.0 Rather than adjust the binding redirects, I used the NPM to upgrade all the Newtonsoft.Json to v6.0.1 and subsequently all the projects references to it became dependent on an assemblyversion for it of 6.0.0.0

I presume thus that when a binding redirect specifies a version of a library that doesn't exist in the solution, and it is successfully fund elsewhere, that other version may become a conflicting version with the locally referenced one.

Edit: It appears that NuGet Package Manager (Console)/Powershell can also regularise the binding redirects, with the following command:

Get-Project –All | Add-BindingRedirect

More info: https://weblog.west-wind.com/posts/2014/Nov/29/Updating-Assembly-Redirects-with-NuGet

TLDR; ensure your binding redirects reference the version of a lib that is available in the project

Caius Jard
  • 72,509
  • 5
  • 49
  • 80