Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nuget update sets bindingRedirects for system.runtime that then fail at runtime

I have a moderately complex application, with a unit test project targetting .NET Framework 4.6.1

If I run the following in Package Management console:

update-package -reinstall -project velogicfit.Sizer3D.Core.UnitTests

... then Nuget adds a bunch of binding redirects to the unit test project's app.config file, redirecting to v4.1.1.0 of things like System.Runtime:

<dependentAssembly>
    <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
</dependentAssembly>

And then, when the project is run (by NCrunch), it fails with the message:

System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

I could possibly fix the error by installing a more recent framework version, but I would rather understand what is causing Nuget to add these binding redirects.

Looking through every DLL in the unit test project's output directory, the highest reference I can see is to system.runtime v4.0.20.0

I have tried asmspy and it also reports that there are some dependencies on 4.0.20.0, but nothing on 4.1.1.0

FWIW, the references to system.runtime v4.0.20.0 all come from other projects of mine in the solution, which are targetting NETStandard 1.4

Questions:

  • How can I find out which framework version corresponds to each of these versions of system.runtime (4.0.0.0, 4.0.20.0, 4.1.1.0)?
  • Is there any logging I can turn on to find out what Nuget is thinking & why it sets the assembly binding redirects to 4.1.1.0?
  • Should my NETStandard 1.4 projects be referencing 4.0.20.0?
like image 921
dbruning Avatar asked Jun 13 '17 02:06

dbruning


1 Answers

I ended up solving this (and some other reference issues) by switching to Paket. Paket helped me get a grip on my direct and transitive dependencies, and I was then able to see what was depending on what and set the binding redirects appropriately.

like image 149
dbruning Avatar answered Jan 02 '23 13:01

dbruning