0

Whenever I call a method that creates new HttpClient(), i get and exception. No clue, as System.Net.Http is already referenced.

    public async Task<Stuff> GetOrder(int id)
    {

        var t = new HttpClient();
    }

enter image description here

    "InnerException": {
        "ClassName": "System.IO.FileNotFoundException",
        "Message": "Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.",

Any ideas?

ShaneKm
  • 20,823
  • 43
  • 167
  • 296
  • Do read [this](https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/) – H H Feb 15 '18 at 13:04
  • That 'specific version' demand is a little odd. Dis you set that on purpose? Why? – H H Feb 15 '18 at 13:06
  • You can try removing the binding redirects, there is a similar question: https://stackoverflow.com/questions/47570912/strange-issue-with-system-net-http-4-2-0-0-not-found?answertab=votes#tab-top – Vivek Sharma Feb 16 '18 at 12:53
  • 1
    I found this when doing clean/rebuild: (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2041,5): warning MSB3277: Found conflicts between different versions of "System.Net.Http" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed. – ShaneKm Feb 16 '18 at 15:10
  • Well, look int it with the package manager and/or remove and re-add the relevant assemblies. – H H Feb 17 '18 at 13:20

1 Answers1

0

The issue was caused by:

Microsoft.Extensions.Configuration.Abstractions

Whenever I had a reference to this assembly, it would throw this error. I needed this as I was using API config stuff. So the fix was to NOT let Resharper add reference to Http.Net but to have HttpClient referenced by NuGet.

<package id="System.Net.Http" version="4.3.3" targetFramework="net461" />
ShaneKm
  • 20,823
  • 43
  • 167
  • 296