Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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
Developer Community or GitHub 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.
When reading from a stream returned by HttpWebResponse.GetResponseStream(), the Read() call is returning 0 when there is an error reading from the stream, causing the caller to incorrectly assume the end of the stream was reached successfully. The correct behavior is to throw an IOException.
This problem also exists for Xamarin.iOS. Bug reported here: https://bugzilla.xamarin.com/show_bug.cgi?id=15665
See this forum post for more details, repro steps, and repro code.
> when there is an error reading from the stream
What error? Do you have a test case which consistently generates this?
WebConnectionStream.Read() doesn't swallow exceptions; the one relevant `catch` block I see rethrows the exception:
What _may_ be happening is that the server is saying that the Content-Length is size X, while the actual data read is Y, Y < X. This would cause you to read fewer bytes than the Stream.Length property implied, and this possibility is mentioned on .NET forums:
Sorry for the overloaded wording. By "error" I meant a real-world network failure (which isn't being translated into a corresponding exception, hence the bug report).
The server is correctly representing the Content-Length in this case. During successful test runs the Content-Length exactly matches the number of bytes read from the stream. Actual bytes < Content-Length only when the network connection breaks while downloading the same exact file that had previously downloaded successfully with actual bytes == Content-Length.
Here's a shorter test case distilled from my longer forum post:
1. Copy my test code and replace the Uri string with something large such as:
or (20.7 MB)
2. change the fileName line to something like this:
string fileName = "world.jpg";
3. Run the code and break the network connection mid-download (unplug a network cable, turn off a network adapter, turn off wifi, turn on airplane mode, etc.)
Expected behavior: responseStream.Read() should throw an IOException.
Actual behavior: responseStream.Read() returns 0
I'm guessing that NetworkStream or maybe even Socket is returning 0 or -1 when it should be throwing an IOException instead.
Thank you for taking the time to submit this report. After reviewing the description of this bug, we believe it no longer affects the current version of Xamarin.Android. If you are still experiencing the issue after updating your packages, please reopen this report with an attached reproduction.