Could not load file or assembly System.Net.Http ve

2019-01-18 09:10发布

I'm porting a Net Framework 4 dll to Net Core. When porting my unit tests project I get an exception running some specific tests (not all).

System.IO.FileLoadException: Could not load file or assembly 'System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

This is the project.json for my dll

 {
  "version": "1.0.0-*",

  "dependencies": {
    "log4net": "2.0.7",
    "NETStandard.Library": "1.6.1",
    "Newtonsoft.Json": "9.0.1",
    "StackExchange.Redis": "1.2.1"
  },

  "frameworks": {
    "netstandard1.6": {
      "imports": "dnxcore50"
    }
  }
}

And this is Packages.config for the unit tests project

<packages>
  <package id="Castle.Core" version="4.0.0" targetFramework="net462" />
  <package id="log4net" version="2.0.7" targetFramework="net462" />
  <package id="Microsoft.Win32.Primitives" version="4.0.1" targetFramework="net462" />
  <package id="Moq" version="4.7.1" targetFramework="net462" />
  <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net462" />
  <package id="StackExchange.Redis" version="1.2.1" targetFramework="net462" />
  <package id="System.Diagnostics.DiagnosticSource" version="4.0.0" targetFramework="net462" />
  <package id="System.IO" version="4.1.0" targetFramework="net462" />
  <package id="System.IO.FileSystem" version="4.0.1" targetFramework="net462" />
  <package id="System.IO.FileSystem.Primitives" version="4.0.1" targetFramework="net462" />
  <package id="System.IO.FileSystem.Watcher" version="4.0.0" targetFramework="net462" />
  <package id="System.Linq" version="4.1.0" targetFramework="net462" />
  <package id="System.Net.Http" version="4.1.1" targetFramework="net462" />
  <package id="System.Net.NameResolution" version="4.0.0" targetFramework="net462" />
  <package id="System.Runtime" version="4.1.0" targetFramework="net462" />
  <package id="System.Runtime.Extensions" version="4.1.0" targetFramework="net462" />
  <package id="System.Security.Cryptography.Algorithms" version="4.2.0" targetFramework="net462" />
  <package id="System.Security.Cryptography.Encoding" version="4.0.0" targetFramework="net462" />
  <package id="System.Security.Cryptography.Primitives" version="4.0.0" targetFramework="net462" />
  <package id="System.Security.Cryptography.X509Certificates" version="4.1.0" targetFramework="net462" />
  <package id="System.Text.RegularExpressions" version="4.1.0" targetFramework="net462" />
  <package id="System.Threading.Thread" version="4.0.0" targetFramework="net462" />
</packages>

8条回答
该账号已被封号
2楼-- · 2019-01-18 09:27

My problem was that my service had a referenced assembly that had a reference to a newer version of System.Net.Http. I've resolved the issue by updating System.Net.Http in the service.

查看更多
Viruses.
3楼-- · 2019-01-18 09:31

Maybe offtop, but my problem was that Azure didn't support the latest .NET Framework.

查看更多
Bombasti
4楼-- · 2019-01-18 09:33

I am agree with Jean. Remove reference to assembly and then add new reference via Nuget! The actual System.Net.Http version doesn't matter. After removing reference to assembly, all works fine, version 4.3.2

查看更多
Deceive 欺骗
5楼-- · 2019-01-18 09:41

Fixed it by updating System.Net.Http to 4.3.1

查看更多
在下西门庆
6楼-- · 2019-01-18 09:48

And now the junior programmer solution.... double check that you are making the updates suggested by Jawen and Jean in Nuget Package Manager in the correct places too. Remember that you might have a solution with your project and a test project, and so double check to update both sets of References.

查看更多
SAY GOODBYE
7楼-- · 2019-01-18 09:50

I had this problem, while I had 10 projects depending on each other. I fixed that by adding the version that it asked for in one of the projects that was dependent on. It was not needed for compilation, but it seems that adding it, fixed the version in other projects while restoring. So it was:

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.

Then:

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.

So I added "System.Net.Http": "4.1.1", in one project..

That actually fixed the problem while it restored 8 projects.

查看更多
登录 后发表回答