Joan Venge
Joan Venge

Reputation: 330992

HttpClient is not found in .NET 4.5

I am trying to use the new HttpClient in .NET 4.5, but Visual Studio complains that it doesn't exist. I have System.Net, but when I type System.Net.Http, it complains for that too.

Am I supposed to download a new distributable for this class?

Upvotes: 31

Views: 61353

Answers (6)

Dmitry Shashurov
Dmitry Shashurov

Reputation: 1704

Add assemly to web.config:

  <system.web>
    <compilation>
      <assemblies>
        <add assembly="System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

Upvotes: 0

Brady Moritz
Brady Moritz

Reputation: 8903

I simply:

  1. Closed Visual Studio
  2. Re-opened it

Boom. It found HttpClient.

Upvotes: 1

WindyHen
WindyHen

Reputation: 328

Start using vs2017, and encounter same problem, when creating Native + PCL, couldn't find the HttpClient, going to Nuget and get Microsoft.Net.Http solve my problems. enter image description here

Upvotes: 10

johnbuen
johnbuen

Reputation: 41

I encountered the issue when I added a class inside the App_Code folder having this HttpClient called in one of my function. Upon spending countless hours I found that the Build Action under Properties for my class is set to Content.

Changing this Build Action to Compile fixed the problem.

Upvotes: 4

The Sammie
The Sammie

Reputation: 1248

I had the same problem. After some digging around, i found you had to install this package and then add the reference to System.Net.Http for it to not complain!

Upvotes: 24

ulrichb
ulrichb

Reputation: 20054

Add a reference to System.Net.Http:

add ref

Upvotes: 45

Related Questions