-1

I want to use this code:

public void SendFile(string uri, string filepath)
{
    using (var client = new WebClient())
    {
        client.Headers.Add("Content-Type", "application/xml");
        byte[] response = client.UploadFile(uri, "POST", filepath);
        return Encoding.ASCII.GetString(response);
    }
}

...but I get the dreaded "The type or namespace name 'WebClient' could not be found (are you missing a using directive or an assembly reference?)"

According to this, WebClient is available in .NET 3.5 (this is a .NET 3.5 / Windows CE project).

Is this unfindability because this is a Windows CE / Compact Framework project that Visual Studio is pretending it doesn't recognize WebClient? Is there a workaround or am I, again, doomed?

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862

1 Answers1

1

The way you interpret MSDN links is completely wrong, but understandable.

Microsoft decided to build .NET Compact Framework/XNA/Silverlight in a "isolated" way, so you cannot rely on the general MSDN links to tell whether a class is available in such ripped frameworks.

http://msdn.microsoft.com/en-us/library/w8xd02k7(v=vs.90).aspx

http://msdn.microsoft.com/en-us/library/ms172548(v=vs.90).aspx

And Visual Studio is smartly following those resolution rules to tell you that WebClient class does not exist.

Developers that target CF are doomed in a way that when hitting missing classes you have to search for alternatives, and sometimes copy Mono's source code in order to fulfill some tasks.

Since Microsoft open sources .NET core source code, you might also copy their source files once available at https://github.com/dotnet/corefx

Lex Li
  • 60,503
  • 9
  • 116
  • 147