0

When I try to run the solution, I'll get an error: Could not load file or assembly 'System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

System.Net.Http version 4.0.0 is always in use. I have tried to update, downgrade and god knows what for hours now. Nothing I've tried works.

This is my project.json:

{
  "dependencies": {
    "Microsoft.AspNetCore.Mvc": "1.0.1",
    "Microsoft.AspNetCore.Routing": "1.0.1",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.2",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.2",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.1.2",
    "Microsoft.Extensions.Configuration.Json": "1.1.2",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.1.2",
    "Microsoft.Extensions.Logging": "1.1.2",
    "Microsoft.Extensions.Logging.Console": "1.1.2",
    "Microsoft.Extensions.Logging.Debug": "1.1.2",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.2",
    "Microsoft.ServiceFabric": "5.6.220",
    "Microsoft.ServiceFabric.AspNetCore.WebListener": "2.6.220",
    "Microsoft.ServiceFabric.Data": "2.6.220",
    "Microsoft.ServiceFabric.Services": "2.6.220",
    "Microsoft.AspNetCore.Mvc.Formatters.Xml": "1.0.1",
    "Microsoft.AspNetCore.Authentication.Cookies": "1.1.1",
    "microsoft.aspnetcore.authentication.jwtbearer": "1.1.1",
    "System.Net.Http": "4.3.2"
  },

  "tools": {
  },

  "frameworks": {
    "net461": {}

  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "**/*.cshtml",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
  }
}

In there I have written "System.Net.Http": "4.3.2", but as you can see in this image, the reference version is 4.0.0:

What am I doing wrong and how can I fix it? I'm getting a bit confused. I declare 4.3.2, the reference is 4.0.0 and the error says 4.1.1? I have searched everywhere for version 4.1.1, but didn't find anything.

Edit: I'm using VS 2015 on a windows 7 machine.

I have also tried to redirect to the correct assembly version in the config json file with no success.

Dandy
  • 115
  • 1
  • 6

2 Answers2

1

For whatever reason VS 2015 would fallback to v4.0.0 of System.Net.Http if multiple package versions were used. What you could do is:

  1. Upgrade your .NET Core projects to v1.1 and use VS 2017.
  2. Remove Microsoft.AspNetCore.Authentication.JwtBearer which has a dependency on System.Net.Http v4.0.0.

Dependencies

If Microsoft.AspNetCore.Authentication.JwtBearer is needed in your project, then #1 might be the only option.

Ignas
  • 4,092
  • 17
  • 28
  • I removed `Microsoft.AspNetCore.Authentication.JwtBearer` and it did nothing. Still the sam issue. I'm installing 2017 now – Dandy Jul 05 '17 at 16:27
  • Delete `project.json.lock` file and restore packages again, just in case. Should look like this: https://i.imgur.com/tjFsuV9.png – Ignas Jul 05 '17 at 16:30
  • I installed VS 17 and the reference shows correct version now, in this case I used 4.1.1.0. But I'm still getting the same error, Could not load file or assembly 'System.Net.Http, Version=4.1.1.0... – Dandy Jul 05 '17 at 19:56
  • I'm getting the following errors in the build log: `(CLR v4.0.30319: xxx.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Net.Primitives\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Primitives.dll'. Module was built without symbols. (CLR v4.0.30319: xxx.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_64\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.` – Dandy Jul 05 '17 at 20:08
  • OK, got it working now. Didn't work with v4.1.1.0. Has to use the latest, v4.3.2.0. Thank you for your help and time, appreciated! – Dandy Jul 05 '17 at 20:43
0

Reference the latest version of System.Net.Http and add to your app.config bindingRedirect like that:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.1.0" />
       </dependentAssembly>
       <!-- Other possible redirects... -->
    </assemblyBinding>
 </runtime>

Please adjust the version and other values in my redirect if needed.

At least that's how it worked before, may be in .Net Core something changed, in that case, you at least have an idea of what to do now.

  • Thanks for your answer. I've already tried that without any success. Still the same issue. – Dandy Jul 05 '17 at 14:04
  • You have to add this redirection in the app.config of the first assembly, that is executed. If you add it to some internal library it's not enough. Also, try to enable fusion log and read logs, maybe you will find something useful. https://stackoverflow.com/questions/255669/how-to-enable-assembly-bind-failure-logging-fusion-in-net – Vladimir Arustamian Jul 05 '17 at 14:12