Bug 46538 - System.Net.WebClient.OpenReadAsync/OpenReadTaskAsync do not work for file:// URLs
Summary: System.Net.WebClient.OpenReadAsync/OpenReadTaskAsync do not work for file:// ...
Status: RESOLVED FIXED
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
URL:
Depends on:
Blocks:
 
Reported: 2016-11-07 15:01 UTC by Patrick Dähne
Modified: 2016-11-20 10:39 UTC (History)
2 users (show)

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


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

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

Note You need to log in before you can comment on or make changes to this bug.