title: Could not load file or assembly 'System.IO, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies
body: <p>Over the last few days, I have been desperately trying to resolve a case of dependency hell I got into after installing a NuGet package which added a bunch of new dependencies from the <code>System.Collections.*</code>, <code>System.Diagnostics.*</code>, <code>System.IO.*</code>, <code>System.Runtime.*</code>, <code>System.Text.*</code>, <code>System.Threading.*</code> and <code>System.Xml.*</code> namespaces. The MVC project I have the issue in targets .Net 4.7.1 currently.</p>
  
  <p>The package installation adds the following binding redirects to my web.config</p>
  
  <pre><code>  &lt;dependentAssembly&gt;
      &lt;assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /&gt;
      &lt;bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" /&gt;
    &lt;/dependentAssembly&gt;
    &lt;dependentAssembly&gt;
      &lt;assemblyIdentity name="System.Runtime.InteropServices" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /&gt;
      &lt;bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" /&gt;
    &lt;/dependentAssembly&gt;
    &lt;dependentAssembly&gt;
      &lt;assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /&gt;
      &lt;bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" /&gt;
    &lt;/dependentAssembly&gt;
    &lt;dependentAssembly&gt;
      &lt;assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /&gt;
      &lt;bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" /&gt;
    &lt;/dependentAssembly&gt;
    &lt;dependentAssembly&gt;
      &lt;assemblyIdentity name="System.Runtime.Extensions" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /&gt;
      &lt;bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" /&gt;
    &lt;/dependentAssembly&gt;
    &lt;dependentAssembly&gt;
      &lt;assemblyIdentity name="System.Linq" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /&gt;
      &lt;bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" /&gt;
    &lt;/dependentAssembly&gt;
    &lt;dependentAssembly&gt;
      &lt;assemblyIdentity name="System.Xml.ReaderWriter" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /&gt;
      &lt;bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" /&gt;
    &lt;/dependentAssembly&gt;
    &lt;dependentAssembly&gt;
      &lt;assemblyIdentity name="System.Linq.Expressions" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /&gt;
      &lt;bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" /&gt;
    &lt;/dependentAssembly&gt;
  </code></pre>
  
  <p>…which results in the exception below:</p>
  
  <pre><code>Could not load file or assembly 'System.IO, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)
  </code></pre>
  
  <p>The highlighted line in the web.config is:</p>
  
  <pre><code>&lt;add assembly="System.IO, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /&gt;
  </code></pre>
  
  <p>I eventually found out that if I removed the bindingRedirect for <code>System.IO</code> it cleared that error and then complained about one of the other items in the list of binding redirects. One by one I removed all of the binding redirects and the problem is resolved.</p>
  
  <p>I'm struggling to understand what is going on here. As an example, if I take a look at the property inspector for System.IO in my references in the Visual Studio project it points to <code>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.1\Facades\System.IO.dll</code> and not the Nuget folder yet if I open the .csproj file in another editor I can see that the reference does, in fact, look as follows:</p>
  
  <pre><code>&lt;Reference Include="System.IO, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"&gt;
    &lt;HintPath&gt;..\packages\System.IO.4.3.0\lib\net462\System.IO.dll&lt;/HintPath&gt;
    &lt;Private&gt;True&lt;/Private&gt;
    &lt;Private&gt;True&lt;/Private&gt;
  &lt;/Reference&gt;
  </code></pre>
  
  <p>Something is definitely wrong here because there are duplicate <code>&lt;Private&gt;True&lt;/Private&gt;</code> entries, I've corrected this once but they are added back. This is an issue for all of the new assemblies. I wonder if there is an issue with the Nuget packages somewhere?</p>
  
  <p>Any help/advice would be appreciated please.</p>