IServiceCollection does not contain a defintion for AddHttpClient

28,600

Solution 1

Aah, I have found the solution. I think services.AddHttpClient work with .net core 2.1. So I updated my .net core version to 2.1 and updated the microsoft packages to 2.1 and it starts working.

Solution 2

You need to install Microsoft.Extensions.Http from NuGet

Share:
28,600
Ask
Author by

Ask

Updated on July 05, 2022

Comments

  • Ask
    Ask almost 2 years

    I am trying to use HttpClient in my .net core 2.0 project and for that I have injected HttpClient in my controller. But when I am trying to configure httpclient in my startup.cs I am getting this error: "IServiceCollection does not contain a defintion for AddHttpClient". I have already referenced using Microsoft.AspNetCore.Http; and using Microsoft.Extensions.DependencyInjection; and here is what I am trying to do:

    services.AddHttpClient<TestController>();
    

    It's working fine in other project with same namespaces but here I am getting the error. Any help?