Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling System.Net.Http within VS 2012 Project

I'm fairly new to JSON development and just getting started is a major task with very little in the way of solutions via Google.

I can't get anywhere without adding system.net.http as part of my project

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Net.Http;

objects like var, HttpWebClient, KeyValuePair throw up an error during compile. Here's what I tried:

  • Reinstalled .NET 4.0
  • Reinstalled .NET 4.5
  • Repackaged library via. NuGet
  • Referenced system.net

No luck. I've even tried referencing the the class in web.config

<compilation targetFramework="4.5">
  <assemblies>
    <add assembly="System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </assemblies>
</compilation>

and again in..

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" />
      <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

An error is thrown on "assemblies"

I'm at my wits end. What am I not referencing or doing wrong where System.Net.Http cannot be used.

like image 960
Nanohurtz Avatar asked Aug 31 '25 02:08

Nanohurtz


2 Answers

In .NET 4.5 System.Net.Http is in it's own assembly, you have to go to "Add References" (right click on the project) and select it.

See the MSDN page for HttpClient: http://msdn.microsoft.com/en-us/library/system.net.http.httpclient.aspx

Assembly: System.Net.Http (in System.Net.Http.dll)

like image 174
mletterle Avatar answered Sep 02 '25 17:09

mletterle


The help system reveals that the System.Net.Http namespace is defined in System.Net.Http.dll which as you say is not listed. A quick search of my own filesystem reveals copies

  • In the GAC
  • In the framework folders for both 32 and 64 bit

On my system those paths are

 C:\Windows\Microsoft.NET\Framework\v4.0.30319
 C:\Windows\Microsoft.NET\Framework64\v4.0.30319

System.Net.Http.WebRequest.dll is on the same paths.

like image 22
Peter Wone Avatar answered Sep 02 '25 17:09

Peter Wone