Bug 28287 - WebException.Response is null under Mono, not null under .net
Summary: WebException.Response is null under Mono, not null under .net
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 3.10.0
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-03-21 01:37 UTC by dj_technohead
Modified: 2017-09-22 21:21 UTC (History)
5 users (show)

Tags:
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 for Bug 28287 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • 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

Related Links:
Status:
NEW

Description dj_technohead 2015-03-21 01:37:37 UTC
With the following code:

  HttpWebRequest request = (HttpWebRequest)WebRequest.CreateHttp(url);
            if (Helpers.Proxy != null) request.Proxy = Helpers.Proxy;

            WebHeaderCollection headers = new WebHeaderCollection();
            headers.Add("Content-Range: bytes */*");
            request.ContentLength = 0;
            request.Headers = headers;
            request.Method = "PUT";
            request.KeepAlive = false;

            HttpWebResponse response = null;
            try
            {
                response = (HttpWebResponse)(request.GetResponse());
                Debug.WriteLine(((HttpWebResponse)response).StatusDescription);
            }
            catch (WebException e)
            {
                Debug.WriteLine(e.Message);
                response = (HttpWebResponse)e.Response;
            }

when run under Windows (.net) and an (expected) WebException occurs:

{"The remote server returned an error: (308) Resume Incomplete."}
    base: {"The remote server returned an error: (308) Resume Incomplete."}
    Response: {System.Net.HttpWebResponse}
    Status: ProtocolError

Running the same under mono:

{System.Net.WebException: Invalid status code: 308 ---> System.Net.ProtocolViolationException: Invalid status code: 308
  at System.Net.HttpWebRequest.Redirect (System.Net.WebAsyncResult result, HttpStatusCode code, System.Net.WebResponse response) [0x000e9] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.8.0.2/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1138 
  at System.Net.HttpWebRequest.CheckFinalStatus (System.Net.WebAsyncResult result) [0x0026d] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.8.0.2/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1691 
  at System.Net.HttpWebRequest.SetResponseData (System.Net.WebConnectionData data) [0x00165] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.8.0.2/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1485 
  --- End of inner exception stack trace ---
  at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x0005e] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.8.0.2/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:969 
  at System.Net.HttpWebRequest.GetResponse () [0x0000e] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.8.0.2/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:985 
  at RedCorners.Vimeo.VimeoClient.Verify (System.String url) [0x00053] in /Users/dj_technohead/Projects/HighSeas/Specialus/Mobile/Framework/Vimeo/VimeoLowLevel.cs:56 }
	Data: Count=0
	HResult: -2146233079
	HelpLink: (null)
	InnerException: {System.Net.ProtocolViolationException: Invalid status code: 308
  at System.Net.HttpWebRequest.Redirect (System.Net.WebAsyncResult result, HttpStatusCode code, System.Net.WebResponse response) [0x000e9] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.8.0.2/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1138 
  at System.Net.HttpWebRequest.CheckFinalStatus (System.Net.WebAsyncResult result) [0x0026d] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.8.0.2/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1691 
  at System.Net.HttpWebRequest.SetResponseData (System.Net.WebConnectionData data) [0x00165] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.8.0.2/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1485 }
	Message: "Invalid status code: 308"
	Response: (null)
	Source: "System"
	StackTrace: "  at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x0005e] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.8.0.2/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:969 \n  at System.Net.HttpWebRequest.GetResponse () [0x0000e] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.8.0.2/src/mono/mcs/class/System/System.Net/HttpWebRequest.cs:985 \n  at RedCorners.Vimeo.VimeoClient.Verify (System.String url) [0x00053] in /Users/dj_technohead/Projects/HighSeas/Specialus/Mobile/Framework/Vimeo/VimeoLowLevel.cs:56 "
	Status: System.Net.WebExceptionStatus.ProtocolError
	TargetSite: {System.Net.WebResponse EndGetResponse(System.IAsyncResult)}
	Static members: 
	Non-public members:


In the case of .net, the WebException.Response object is not null, but under mono it is null.
Comment 1 dj_technohead 2015-05-12 18:18:32 UTC
Is there any progress on this? This is a pretty bad bug IMO. I've reproduced it going against YouTube as well. Both services use a status code HTTP 308 (Resume Incomplete) to inform the client how many bytes are left for the upload.
Comment 2 dj_technohead 2015-05-12 18:23:48 UTC
It seems like all that needs to be done is to return the HttpResponse in the WebException.Response.
Comment 3 juanjo.a 2017-03-03 12:00:01 UTC
Why don't you fix this bug? it was reported almost 2 years ago. 

Some services like Youtube or Google Drive use 308 responses for partial uploads and this bug is blocking Xamarin applications from using it. 

It also should be really easy to fix, just include the server response in WebException.Response like .NET Framework does.
Comment 4 Marek Safar 2017-03-09 15:23:35 UTC
What url are you using to test this?
Comment 5 juanjo.a 2017-03-09 18:27:33 UTC
For example, uploading files in multiple chunks to Google Drive using their API:

https://developers.google.com/drive/v3/web/resumable-upload
Comment 6 Paul Kiar 2017-09-22 21:21:27 UTC
If you use HttpWebRequest you can set HttpWebRequest.AllowAutoRedirect to false to avoid this exception. I haven't tried HttpClient.AllowAutoRedirect but it may work.