System.Net.Http: missing from namespace? (using .net 4.5)

后端 未结 16 2223
我寻月下人不归
我寻月下人不归 2020-11-27 17:57

TL; DR: I\'m new to this language and have no idea what I\'m doing

here is my class so far:

using System;
using System.Collections.Generic;
using Sys         


        
相关标签:
16条回答
  • 2020-11-27 18:07

    How I solved it.

    1. Open project (!) "Properties", choose "Application", select targeting framework ".Net Framework 4.5"
    2. Right click on your project -> Add reference
    3. Make sure that in "Assemblies" -> "Extensions" option "System.Net.Http" is unchecked
    4. Go to "Assemblies" -> "Framework" and select "System.Net.Http" and "System.Net.Http" options
    5. 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.

    0 讨论(0)
  • 2020-11-27 18:10

    HttpClient lives in the System.Net.Http namespace.

    You'll need to add:

    using System.Net.Http;
    

    And make sure you are referencing System.Net.Http.dll in .NET 4.5.


    The code posted doesn't appear to do anything with webClient. Is there something wrong with the code that is actually compiling using HttpWebRequest?


    Update

    To open the Add Reference dialog right-click on your project in Solution Explorer and select Add Reference.... It should look something like:

    enter image description here

    0 讨论(0)
  • 2020-11-27 18:15

    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.

    0 讨论(0)
  • 2020-11-27 18:15

    I had this issue after upgrading to .NET Framework 4.7.2. I found out that Nuget package for System.Net.Http is no longer recommended. Here are workarounds:

    • Single-name references are removed by the SDK
    • Nuget package for System.Net.Http on .NET Framework 4.7.2 and newer versions
    0 讨论(0)
  • 2020-11-27 18:15

    In Visual Studio you can use nuget to load the package

    Microsoft.AspNet.WebApi.WebHost
    
    0 讨论(0)
  • 2020-11-27 18:16

    To solve the problem :

    1. Go to your solution explorer.
    2. Right click on the project name and choose add
    3. Select references and allow the .Net framework 4.5 to finish loading
    4. Scroll down and select System.Net.Http and click ok.

    Problem solved.

    0 讨论(0)
提交回复
热议问题