WebClient could not be found

16,058

Make sure you have reference to System.dll in your project.

Also either include using System.Net; to usings directive section of the source code where you're planning to use WebClient or use its fully-qualified name, i.e.:

var client = new System.Net.WebClient()
Share:
16,058
M Zeinstra
Author by

M Zeinstra

BIO

Updated on October 11, 2022

Comments

  • M Zeinstra
    M Zeinstra over 1 year

    I've already search on Stack Overflow (and google), but can't find the specific answer that solves my problem.

    I want to read some content out of a page. I've tried to use Webclient, but that gives me this error:

    The type or namespace name 'WebClient' could not be found (ae you missing a using directive or an assembly reference?)

    I've tried to search on google how to solve this error, but didn't find a correct answer (I've also tried HttpClient, same result).

    How do I make sure that I get the content of his specific page?

    Btw, this is what I have right now:

    WebClient client = new WebClient();
    // Use google as test page
    string downloadString = client.DownloadString("http://www.gooogle.com");
    

    And I'm using Visual Studio 2015 Community and ASP.Net v5

    • Salah Akbari
      Salah Akbari about 8 years
      Did you add using System.Net; to your using directive?
    • M Zeinstra
      M Zeinstra about 8 years
      @S.Akbari Yes, I tried.. Then I get the error: A using clause must precede all other elements defined in the namespace except extern alias declarations
    • Salah Akbari
      Salah Akbari about 8 years
      OK. Probably you have not placed it at the beginning of the file!
    • M Zeinstra
      M Zeinstra about 8 years
      @S.Akbari I did (see comment at the answer)
  • M Zeinstra
    M Zeinstra about 8 years
    Thanks! var client = new System.Net.WebClient() works perfect! But do you also know why using System.Net; gives me this error?: A using clause must precede all other elements defined in the namespace except extern alias declarations
  • Andrey Korneyev
    Andrey Korneyev about 8 years
    @MZeinstra using directives should be at the very beginning of the file. Where do you placed it?
  • M Zeinstra
    M Zeinstra about 8 years
    I've placed this <script runat="server">using System.Net;</script> at the very top of my .aspx file
  • Andrey Korneyev
    Andrey Korneyev about 8 years
    @MZeinstra hmmm... you've mentioned ASP.NET v5 so aspx was last thing that came in my mind. In apsx file you have to use <%@ Import Namespace="System.Net" %> instead.
  • M Zeinstra
    M Zeinstra about 8 years
    Ahh okay, sorry. That works just fine :D What am I using then? You think?
  • Mohamad Mahmoud Darwish
    Mohamad Mahmoud Darwish over 7 years
    how i can add System.dll