title: Library version conflicts in .NET: System.Net.Http
body: <p>I am trying to use NuGet Package Manager Console to deploy changes to the database. When I issue the <code>Update-Database</code> command, it fails with an error message saying:</p>
  
  <pre><code>Could not load file or assembly 'System.Net.Http, Version=4.1.1.1,
    Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its
    dependencies. The system cannot find the file specified.
  </code></pre>
  
  <p>My projects targets .NET 4.5.2 which as far as I can tell, provides <code>System.Net.Http</code> in version <code>4.0.0.0</code>. Thus, the incriminated library is not laid in the binary output directory. When I download the <code>4.1.1.1</code> version (NuGet package version 4.3.2) and copy it into the binary output directory, along with my DLLs, I get another error message:</p>
  
  <pre><code>Loading this assembly would produce a different grant set from other
    instances. (Exception from HRESULT: 0x80131401)
  </code></pre>
  
  <p>In both cases the exception is <code>System.IO.FileLoadException</code> and it is thrown in <code>Microsoft.Rest.ServiceClient'1.CreateRootHandler()</code>. I checked the source code of that function and it in fact references .NET 4.5 and <code>System.Net.Http</code>:</p>
  
  <pre><code>  protected static HttpClientHandler CreateRootHandler()
    {
      // Create our root handler
  #if NET45
      return new WebRequestHandler();
  #else
      return new HttpClientHandler();
  #endif
    }
  </code></pre>
  
  <p>However, nowhere I can find the exact version number of <code>System.Net.Http</code>. Finally, I used ILSpy to inspect <code>Microsoft.Rest.ClientRuntime</code> and it seems to depend on <code>System.Net.Http</code> in version <code>4.0.0.0</code>.</p>
  
  <p><a href="https://i.stack.imgur.com/9Gtwa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9Gtwa.png" alt="ILSpy inspection into Microsoft.Rest.ClientRuntime"></a></p>
  
  <p>I have also tried removing all references to <code>System.Net.Http</code> and installing the newest NuGet (4.3.2). That lead to subsequent errors with missing methods:</p>
  
  <pre><code>Method not found: 'Void Microsoft.Azure.KeyVault.KeyVaultClient..ctor(
    AuthenticationCallback, System.Net.Http.DelegatingHandler[])'.
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Method not found: 'Void Microsoft.Rest.ServiceClient`1..ctor(
    System.Net.Http.DelegatingHandler[])'.
  </code></pre>
  
  <p>which I solved by copying the right DLL from the respective NuGet into the deployment directory. This finally leads back to:</p>
  
  <pre><code>Loading this assembly would produce a different grant set from other
    instances. (Exception from HRESULT: 0x80131401)
  </code></pre>
  
  <p>What am I missing?</p>