1

I am trying to use NuGet Package Manager Console to deploy changes to the database. When I issue the Update-Database command, it fails with an error message saying:

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.

My projects targets .NET 4.5.2 which as far as I can tell, provides System.Net.Http in version 4.0.0.0. Thus, the incriminated library is not laid in the binary output directory. When I download the 4.1.1.1 version (NuGet package version 4.3.2) and copy it into the binary output directory, along with my DLLs, I get another error message:

Loading this assembly would produce a different grant set from other
  instances. (Exception from HRESULT: 0x80131401)

In both cases the exception is System.IO.FileLoadException and it is thrown in Microsoft.Rest.ServiceClient'1.CreateRootHandler(). I checked the source code of that function and it in fact references .NET 4.5 and System.Net.Http:

  protected static HttpClientHandler CreateRootHandler()
  {
    // Create our root handler
#if NET45
    return new WebRequestHandler();
#else
    return new HttpClientHandler();
#endif
  }

However, nowhere I can find the exact version number of System.Net.Http. Finally, I used ILSpy to inspect Microsoft.Rest.ClientRuntime and it seems to depend on System.Net.Http in version 4.0.0.0.

ILSpy inspection into Microsoft.Rest.ClientRuntime

I have also tried removing all references to System.Net.Http and installing the newest NuGet (4.3.2). That lead to subsequent errors with missing methods:

Method not found: 'Void Microsoft.Azure.KeyVault.KeyVaultClient..ctor(
  AuthenticationCallback, System.Net.Http.DelegatingHandler[])'.

and

Method not found: 'Void Microsoft.Rest.ServiceClient`1..ctor(
  System.Net.Http.DelegatingHandler[])'.

which I solved by copying the right DLL from the respective NuGet into the deployment directory. This finally leads back to:

Loading this assembly would produce a different grant set from other
  instances. (Exception from HRESULT: 0x80131401)

What am I missing?

Lukasz
  • 148
  • 11
  • Were you able to solve this? I am having the same issue right now, and I've tried plenty of potential solutions I found on the web but none seems to work... – Nahuel Prieto Nov 17 '17 at 22:21
  • 1
    Nope, but I used the migrate.exe that comes with entity framework and that unblocked deploying changes to the database. I think visual studio is still blocked (that is, the package manager console) but I simply don't care anymore. – Lukasz Nov 17 '17 at 22:24

1 Answers1

1

After finding that Kunal's answer here:

MongoDB client throws a FileNotFoundException in mscorlib

worked for me, I tried changing the version number for System.Net.Http. I have the System.Net.Http version 4.3.3 installed targeting net462 and this worked for me:

<dependentAssembly>
    <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
    <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0"/>
</dependentAssembly>
gene
  • 338
  • 2
  • 9