System.Net.Webclient not working 'WebClient' could not be found
15,194
Given your tags, it sounds like you may be building a Windows Store app - in which case you need to use HttpClient
instead of WebClient
.
Author by
Iban Arriola
Updated on June 12, 2022Comments
-
Iban Arriola almost 2 years
I am trying to work with WebClient but it is giving me errors so I check in several forums (included this one) and they where telling to put
In the top of the file:
using System.Net
And after where I want use the WebClient:
WebClient webClient = new WebClient(); webClient.DownloadFile ("http://mysite.com/myfile.txt", @"c:\myfile.txt");
And I get this error:
The type or namespace name 'WebClient' could not be found (are you missing a using directive or an assembly reference?)
In the other forums the code that I just wrote above seems to be the solution but is not working for me.
-
Mohamad Mahmoud Darwish almost 7 yearswhat if my class library already using webClient and i want to use it on Windows Store App
-
Jon Skeet almost 7 years@MikeDarwish: Then you should change it to use
HttpClient
- it's as simple as that. You just can't useWebClient
in Windows Store apps, as far as I'm aware. -
Mohamad Mahmoud Darwish almost 7 years@JonSkeet but my class already using functions on WebClient public class CookieAwareWebClient : WebClient
-
Mohamad Mahmoud Darwish almost 7 years@JonSkeet actually that is because i am using class library and i am trying to reference this library from uwp,keep in your mind i am already using this librray on my xamarin.forms.Droid project
-
Jon Skeet almost 7 years@MikeDarwish: That doesn't magically make WebClient available in UWP though. Just because you want it to be feasible doesn't make it so.
-
Mohamad Mahmoud Darwish almost 7 years@JonSkeet .. I understand you, i am trying to use same library on uwp & android projects on Xamarin.forms .thx
-
Jon Skeet almost 7 years@MikeDarwish: And I'm saying that you'll need to either change the project to use HttpClient (assuming it's available in the version you're targeting) or use different implementatations. If you package up your library in a NuGet package, you could depend on the same package from both places, but with different implementations based on the target platforms.