Bug 46538 - System.Net.WebClient.OpenReadAsync/OpenReadTaskAsync do not work for file:// URLs
Summary: System.Net.WebClient.OpenReadAsync/OpenReadTaskAsync do not work for file:// ...
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 4.6.0 (C8)
Hardware: All All
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
Depends on:
Reported: 2016-11-07 15:01 UTC by Patrick Dähne
Modified: 2016-11-20 10:39 UTC (History)
2 users (show)

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

Test case (543 bytes, text/plain)
2016-11-07 15:01 UTC, Patrick Dähne

Description Patrick Dähne 2016-11-07 15:01:19 UTC
Created attachment 18354 [details]
Test case

System.Net.WebClient.OpenReadAsync/OpenReadTaskAsync do not work for file:// URLs. See the test case attached to this bug report. Compile the test code like this:

mcs -debug webclienttest.cs

and start it like this:

mono --debug webclienttest.exe webclienttest.cs

You'll get the following exception:

Unhandled Exception:
System.InvalidCastException: Specified cast is not valid.
  at System.Net.WebClient.OpenReadAsyncCallback (System.IAsyncResult result) [0x00000] in /private/tmp/source-mono-4.6.0-c8sr0/bockbuild-mono-4.6.0-branch-c8sr0/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/referencesource/System/net/System/Net/webclient.cs:1803 
  at System.Net.LazyAsyncResult.Complete (System.IntPtr userToken) [0x00047] in /private/tmp/source-mono-4.6.0-c8sr0/bockbuild-mono-4.6.0-branch-c8sr0/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/referencesource/System/net/System/Net/_LazyAsyncResult.cs:415 

The problem is the following line 1803 in the function "OpenReadAsyncCallback" in the file "mono/mcs/class/referencesource/System/net/System/Net/webclient.cs":

var lazyAsyncResult = (WebAsyncResult) result;

When using file URLs, the incoming result is not a System.Net.WebAsyncResult, instead it is a System.Net.LazyAsyncResult, therefore the type cast fails.
Comment 1 Marek Safar 2016-11-20 10:39:30 UTC
Fixed in master

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.

Create a new report for Bug 46538 on Developer Community or GitHub if you have new information to add and do not yet see a matching report.

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

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.

Related Links: