Is there any way to use a WebClient
in a .NET Core application?
If I build the application I get the following error:
Severity Code Description Project File Line
Error CS0246 The type or namespace name 'WebClient' could not be found (are you missing a using directive or an assembly reference?)
I think WebClient
is not a part of .NET Core, but is there any alternative?
As of .Net Standard 2.0, WebClient is now available to any implementations of the standard, including .Net Core. However, the Stack Overflow question "Need help deciding between HttpClient and WebClient" has some fairly good answers as to why you should be using the HttpClient
instead.
One of the drawbacks mentioned is that there is no built-in progress reporting in the HttpClient
. However, because it is using streams, it is possible to write your own. The answers to "How to implement progress reporting for Portable HttpClient" provides an example for reporting the progress of the response stream.
If you're targeting prior versions of the standard, you'll need to use HttpClient
as WebClient
is not available prior to .Net Standard 2.0.
WebClient
is now available in .Net Standard 2.0
https://docs.microsoft.com/en-gb/dotnet/api/system.net.webclient?view=netstandard-2.0