Search code examples
c#.netazure-service-fabric

Service Fabric Service with HttpClient throws exception


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?


Solution

  • 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" />