System.Net.Http : 네임 스페이스에서 누락 되었습니까? (.net 4.5 사용)
TL; DR : 저는이 언어를 처음 사용하고 제가 무엇을하는지 모르겠습니다.
지금까지 내 수업은 다음과 같습니다.
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Web;
using System.Net;
using System.IO;
public class MyClass
{
private const string URL = "https://sub.domain.com/objects.json?api_key=123";
private const string data = @"{""object"":{""name"":""Title""}}";
public static void CreateObject()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = data.Length;
StreamWriter requestWriter = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);
requestWriter.Write(data);
requestWriter.Close();
try
{
// get the response
WebResponse webResponse = request.GetResponse();
Stream webStream = webResponse.GetResponseStream();
StreamReader responseReader = new StreamReader(webStream);
string response = responseReader.ReadToEnd();
responseReader.Close();
}
catch (WebException we)
{
string webExceptionMessage = we.Message;
}
catch (Exception ex)
{
// no need to do anything special here....
}
}
static void Main(string[] args)
{
MyClass.CreateObject();
}
}
csc filename.cs를 수행하면 다음 오류가 발생합니다.
형식 또는 네임 스페이스 이름 'Http'가 네임 스페이스 'System.Net'에 없습니다 (어셈블리 참조가 누락 되었습니까?).
HttpClient
에 살고 System.Net.Http
네임 스페이스.
다음을 추가해야합니다.
using System.Net.Http;
System.Net.Http.dll
.NET 4.5에서 참조하고 있는지 확인하십시오 .
게시 된 코드는 webClient
. 실제로 사용하여 컴파일하는 코드에 문제가 HttpWebRequest
있습니까?
최신 정보
To open the Add Reference dialog right-click on your project in Solution Explorer and select Add Reference.... It should look something like:
NuGet > Microsoft ASP.NET Web API Client Libraries
How I solved it.
- Open project (!) "Properties", choose "Application", select targeting framework ".Net Framework 4.5"
- Right click on your project -> Add reference
- Make sure that in "Assemblies" -> "Extensions" option "System.Net.Http" is unchecked
- Go to "Assemblies" -> "Framework" and select "System.Net.Http" and "System.Net.Http" options
- That`s all!
In my case i had at the beginning .Net 4.0 and "Assemblies" -> "Extensions" option "System.Net.Http" with version 2.0.0.0. After my actions "Assemblies" -> "Framework" options "System.Net.Http" and "System.Net.Http" had the same 4.0.0.0 version.
Visual Studio Package Manager Console > Install-Package Microsoft.AspNet.WebApi.Client
Assuming that your using Visual Studio 10, you can download an install that includes System.Net.Http, for Visual Studio 10 here: download MVC4 for VS10
Once you've installed it, right click on the References folder in the VS Project and then select Add Reference. Then, select the Browse tab. Navigate to the assemblies install path for the MVC4 install (usually in Program Files(x86)/Microsoft ASP.NET/ASP.NET MVC4/assemblies) and select the assembly named 'System.Net.Http.dll'. Now you can add your 'using System.Net.Http' at the top of your code and begin creating HttpClient connections.
You need to have a Reference to the System.Web.Http
assembly which has the HTTPClient
class, your trying to use. Try adding the below line before your class declaration
using System.Web.Http;
If you still get the Error, try doing this in Visual Studio
- Right click on the References folder on your project.
- Select Add Reference.
- Select the .NET tab (or select the Browse button if it is not a .NET Framework assembly).
- Double-click the assembly containing the namespace in the error message (
System.Web.Http.dll
). - Press the OK button.
just go to add reference then add
system.net.http
For me, it was getting the nuget package Microsoft.Net.Http .(https://blogs.msdn.microsoft.com/bclteam/p/httpclient/)
You'll need a using System.Net.Http
at the top.
HttpClient is new in .net 4.5. You should probably be using HttpWebRequest.
use system.Net,
system.Net.WebRequest
i had similar issue or same isue and fixed it recently. however i also had system.net.http added before but that did not solve it.
I continued to get the Error even after adding the using System.Net.Http to the references in android and i had already installed the Nugget Package microsoft.net.http.
It turned out I hand't added the System.Net.Http to the iOS project, when I did, it solved the problem.
To solve the problem :
- Go to your solution explorer.
- Right click on the project name and choose add
- Select references and allow the .
Net framework 4.5
to finish loading - Scroll down and select
System.Net.Http
and click ok.
Problem solved.
Making the "Copy Local" property True for the reference did it for me. Expand References, right-click on System.Net.Http and change the value of Copy Local property to True in the properties window. I'm using VS2019.
In Visual Studio you can use nuget to load the package
Microsoft.AspNet.WebApi.WebHost
참고URL : https://stackoverflow.com/questions/9611316/system-net-http-missing-from-namespace-using-net-4-5
'program tip' 카테고리의 다른 글
Java에서 분수를 나타내는 가장 좋은 방법은 무엇입니까? (0) | 2020.08.28 |
---|---|
Python에서 열린 파일에서 경로 가져 오기 (0) | 2020.08.28 |
Matplotlib로 2D 히트 맵 플로팅 (0) | 2020.08.28 |
JavaScript에서 DOM 요소의 유형 테스트 (0) | 2020.08.28 |
JavaScript 또는 jQuery를 사용하여 Mac OS X 또는 Windows 컴퓨터를 감지하는 가장 좋은 방법 (0) | 2020.08.28 |