Bug 52555 - WebClient.DownloadString not returning inside a task
Summary: WebClient.DownloadString not returning inside a task
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 4.6.0 (C8)
Hardware: PC All
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2017-02-16 06:43 UTC by sidcup
Modified: 2018-03-13 11:07 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description sidcup 2017-02-16 06:43:49 UTC
I'm trying to use a webclient inside a task, see for code: http://stackoverflow.com/questions/42265198/cannot-get-webclient-downloadstring-to-download-inside-a-task-on-mono

The WriteLines are only to indicate where the task was delaying. The string is not returned and so "5" is not displayed. Instead I only receive timeouts. Why is this happening? It works without a hitch on .Net framework 4.5. It does not work on mono linux nor windows.

            var urls5 = urls.Take(100);
            var elapsed5 = Test<WebClient>(urls5);
            Console.WriteLine("Webclient:" + elapsed5);

        static TimeSpan Test<T>(IEnumerable<string> urls) where T : WebClient, new()
            var sw = new System.Diagnostics.Stopwatch();


            var tasks = new List<Task>();

            foreach (var u in urls)
                tasks.Add(Task.Run(() =>
                    using (var wc = new T())
                        var str = wc.DownloadString(u);
                        var hap = new HtmlAgilityPack.HtmlDocument();

                        var asdf = hap.DocumentNode.InnerText + " ";



            return sw.Elapsed;
Comment 1 sidcup 2017-02-16 07:29:08 UTC
A little background info, the HtmlAgilityPack code is part of a bigger project trying to trackdown what I think is a further issue where code pulling and processing data appears to be significantly faster on Windows than linux/mono (on a server where wget can pull the data down at blistering speeds). This is a separate issue that I will focus on after this issue is dealt with.
Comment 2 Marek Safar 2017-04-03 15:45:14 UTC
Could you attach complete repro we can use to reproduce?
Comment 3 Marek Safar 2018-03-13 11:07:21 UTC
We have not received the requested information. If you are still experiencing this issue please provide all the requested information and reopen the bug report.

Thank you!