{"action":"opened","issue":{"url":"https://api.github.com/repos/xamarin/xamarin-android/issues/1282","repository_url":"https://api.github.com/repos/xamarin/xamarin-android","labels_url":"https://api.github.com/repos/xamarin/xamarin-android/issues/1282/labels{/name}","comments_url":"https://api.github.com/repos/xamarin/xamarin-android/issues/1282/comments","events_url":"https://api.github.com/repos/xamarin/xamarin-android/issues/1282/events","html_url":"https://github.com/xamarin/xamarin-android/issues/1282","id":295177901,"number":1282,"title":"System.ObjectDisposedException when using AndroidClientHandler with POST-requests where the response is a 302 redirect","user":{"login":"rros","id":279664,"avatar_url":"https://avatars3.githubusercontent.com/u/279664?v=4","gravatar_id":"","url":"https://api.github.com/users/rros","html_url":"https://github.com/rros","followers_url":"https://api.github.com/users/rros/followers","following_url":"https://api.github.com/users/rros/following{/other_user}","gists_url":"https://api.github.com/users/rros/gists{/gist_id}","starred_url":"https://api.github.com/users/rros/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rros/subscriptions","organizations_url":"https://api.github.com/users/rros/orgs","repos_url":"https://api.github.com/users/rros/repos","events_url":"https://api.github.com/users/rros/events{/privacy}","received_events_url":"https://api.github.com/users/rros/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-07T15:23:11Z","updated_at":"2018-02-07T15:23:11Z","closed_at":null,"author_association":"NONE","body":"### Steps to Reproduce\r\n\r\n1. Configure the HttpClient to use the AndroidClientHandler.\r\n2. Perform a POST-request **with a request body** to an URL where the response is a 302 redirect.\r\n3. An ObjectDisposedException is thrown from the WriteRequestContentToOutput-method.\r\n\r\nThis is reproducible with the following code:\r\n```csharp\r\nnamespace App8\r\n{\r\n    using System;\r\n    using System.Net.Http;\r\n    using System.Text;\r\n    using System.Threading.Tasks;\r\n\r\n    using Android.App;\r\n    using Android.OS;\r\n\r\n    using Xamarin.Android.Net;\r\n\r\n    [Activity(MainLauncher = true)]\r\n    public class MainActivity : Activity\r\n    {\r\n        protected override async void OnCreate(Bundle savedInstanceState)\r\n        {\r\n            base.OnCreate(savedInstanceState);\r\n\r\n            await this.PerformPostRedirectGetAsync(new HttpClientHandler(), false);     // POST -> 302 Found -> GET -> 200 OK\r\n            await this.PerformPostRedirectGetAsync(new HttpClientHandler(), true);      // POST -> 302 Found -> GET -> 200 OK\r\n            await this.PerformPostRedirectGetAsync(new AndroidClientHandler(), false);  // POST -> 302 Found -> GET -> 200 OK\r\n            await this.PerformPostRedirectGetAsync(new AndroidClientHandler(), true);   // POST -> 302 Found -> System.ObjectDisposedException: Cannot access a closed Stream.\r\n\r\n            // Set our view from the \"main\" layout resource\r\n            this.SetContentView(Resource.Layout.Main);\r\n        }\r\n\r\n        private async Task PerformPostRedirectGetAsync(HttpMessageHandler httpMessageHandler, bool withRequestContent)\r\n        {\r\n            // This URL returns a 302 Found to https://httpbin.org/get\r\n            const string Url = \"https://httpbin.org/redirect-to?url=https%3A%2F%2Fhttpbin.org%2Fget\";\r\n\r\n            try\r\n            {\r\n                var client = new HttpClient(httpMessageHandler);\r\n\r\n                var request = new HttpRequestMessage(HttpMethod.Post, Url);\r\n                if (withRequestContent)\r\n                {\r\n                    request.Content = new StringContent(\"{}\", Encoding.UTF8, \"application/json\");\r\n                }\r\n\r\n                var response = await client.SendAsync(request).ConfigureAwait(false);\r\n\r\n                System.Diagnostics.Debug.WriteLine(\r\n                    $\"Response success: {response.IsSuccessStatusCode}, statuscode: {response.StatusCode} ({(int)response.StatusCode})\");\r\n\r\n                var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);\r\n\r\n                System.Diagnostics.Debug.WriteLine(content);\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                System.Diagnostics.Debug.WriteLine(e.Message);\r\n            }\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n### Expected Behavior\r\nThe HttpClient should follow the redirect and issue a GET-request to the URL from the Location-header\r\n\r\n### Actual Behavior\r\nSystem.ObjectDisposedException: Cannot access a closed Stream.\r\nStacktrace:\r\n```\r\n  at System.IO.MemoryStream.CopyToAsync (System.IO.Stream destination, System.Int32 bufferSize, System.Threading.CancellationToken cancellationToken) [0x00037] in /Users/builder/jenkins/workspace/xamarin-android-d15-5/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/io/memorystream.cs:433 \r\n  at Xamarin.Android.Net.AndroidClientHandler+<WriteRequestContentToOutput>d__43.MoveNext () [0x00089] in /Users/builder/data/lanes/5749/75f8c683/source/xamarin-android/src/Mono.Android/Xamarin.Android.Net/AndroidClientHandler.cs:319 \r\n--- End of stack trace from previous location where exception was thrown ---\r\n  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/jenkins/workspace/xamarin-android-d15-5/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:152 \r\n  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Users/builder/jenkins/workspace/xamarin-android-d15-5/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 \r\n  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Users/builder/jenkins/workspace/xamarin-android-d15-5/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 \r\n  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Users/builder/jenkins/workspace/xamarin-android-d15-5/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 \r\n  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /Users/builder/jenkins/workspace/xamarin-android-d15-5/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:113 \r\n  at Xamarin.Android.Net.AndroidClientHandler+<DoProcessRequest>d__44.MoveNext () [0x002a5] in /Users/builder/data/lanes/5749/75f8c683/source/xamarin-android/src/Mono.Android/Xamarin.Android.Net/AndroidClientHandler.cs:391 \r\n--- End of stack trace from previous location where exception was thrown ---\r\n  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/jenkins/workspace/xamarin-android-d15-5/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:152 \r\n  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Users/builder/jenkins/workspace/xamarin-android-d15-5/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 \r\n  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Users/builder/jenkins/workspace/xamarin-android-d15-5/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 \r\n  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Users/builder/jenkins/workspace/xamarin-android-d15-5/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 \r\n  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Users/builder/jenkins/workspace/xamarin-android-d15-5/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535 \r\n  at Xamarin.Android.Net.AndroidClientHandler+<SendAsync>d__39.MoveNext () [0x001e2] in /Users/builder/data/lanes/5749/75f8c683/source/xamarin-android/src/Mono.Android/Xamarin.Android.Net/AndroidClientHandler.cs:278 \r\n--- End of stack trace from previous location where exception was thrown ---\r\n  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/jenkins/workspace/xamarin-android-d15-5/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:152 \r\n  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Users/builder/jenkins/workspace/xamarin-android-d15-5/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 \r\n  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Users/builder/jenkins/workspace/xamarin-android-d15-5/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 \r\n  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Users/builder/jenkins/workspace/xamarin-android-d15-5/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 \r\n  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Users/builder/jenkins/workspace/xamarin-android-d15-5/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535 \r\n  at System.Net.Http.HttpClient+<SendAsyncWorker>d__49.MoveNext () [0x00080] in /Users/builder/jenkins/workspace/xamarin-android-d15-5/xamarin-android/external/mono/mcs/class/System.Net.Http/System.Net.Http/HttpClient.cs:276 \r\n--- End of stack trace from previous location where exception was thrown ---\r\n```\r\n\r\n### Version Information\r\nXamarin.Android SDK   8.1.5.0 (HEAD/75f8c6838)"}}
{"actor":{"display_login":"rros"}}