''HttpClientFactory' does not exist in the current context
I'm writing an application in C#. It pulls the data from Cloudant NoSQL DB.
But when I'm trying to create the Http client:
HttpClient client = HttpClientFactory.Create(new LoggingHandler());
the compiler throws error saying that
'HttpClientFactory' does not exist in the current context
I have also included:
using System.Net.Http;"
at the top.
I still cannot find where the error is.
Could someone please throw some light.
Solution 1:[1]
Install the Microsoft.AspNet.WebApi.Client nuget package.
VS -> Tools -> Nugetpackagemanager -> Package manager console
Install-Package Microsoft.AspNet.WebApi.Client
or (specific version)
Install-Package Microsoft.AspNet.WebApi.Client -Version 5.2.2
Solution 2:[2]
FYI I had the same error and fixed it by adding a new reference:
System.Net.Http.Formatting
Solution 3:[3]
I had the same error. The reason was that I was trying to install the most up to date version of Microsoft.AspNet.WebApi.Client nuget package targeting netcoreapp1.1 version of my project, and these are incompatible (if you try to install the nuget package through the Package Manager Console it'll display you the error). I solved it upgrading my project to .NET Core 2. For more info on how to migrate from .NET Core 1.x to 2 follow this link: https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/
Solution 4:[4]
You need to install the follow nuget package: Microsoft.Extensions.Http
Install-Package Microsoft.Extensions.Http
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | CraftyFella |
Solution 2 | fret |
Solution 3 | Tofetopo |
Solution 4 |