Bug 45927 - EndGetResponse throws InvalidOperationException after reconnection
Summary: EndGetResponse throws InvalidOperationException after reconnection
Status: CONFIRMED
Alias: None
Product: iOS
Classification: Xamarin
Component: BCL Class Libraries (show other bugs)
Version: XI 10.0 (iOS10)
Hardware: PC Mac OS
: Normal normal
Target Milestone: Future Cycle (TBD)
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-10-26 16:24 UTC by ostapdemkiv
Modified: 2016-10-27 15:23 UTC (History)
4 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 45927 on Developer Community or GitHub 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: 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

Related Links:
Status:
CONFIRMED

Description ostapdemkiv 2016-10-26 16:24:09 UTC
I have this code: 

 var request = (HttpWebRequest)WebRequest.Create(@"http://www.xamarin.com");
                IAsyncResult result = request.BeginGetResponse(null, null);

                if (!result.AsyncWaitHandle.WaitOne(2000))
                {
                    request.Abort();
                    return;
                }
                try
                {
                    using (var response = (HttpWebResponse)request.EndGetResponse(result))
                    {
                    }
                }
                catch (Exception ex)
                {
                    // InvalidOperationException..
                }

Steps to reproduce
1. Launch app.
2. Disable internet connection
3. Run this code (for example attach it to button) 
4. As expected exception is thrown
5. Reconnect to internet
6. Run this code. InvalidOperationException is thrown every time 

This code works good if app is always online. It is reproducing on Xamarin.iOs and Xamarin.Mac.
Comment 1 Vincent Dondain [MSFT] 2016-10-27 12:42:10 UTC
Hey, I just tried with a quick Mac template, added a button and hooked up the code you mentioned above and it works just fine.

Using some Console.WriteLine I'm getting a response with an "ok" status when clicking with an internet connection then a `Exception: System.Net.WebException: Error: ConnectFailure (Network is unreachable) ---> System.Net.Sockets.SocketException: Network is unreachable` when the network is off, then the response with the ok status again when it's turned back on.

Could you please attach 2 things to this bug in order for us to understand what your issue it:

- A test case / project sample (Mac or iOS) that doesn't work for you locally and has the above code.
- Your about information:
The easiest way to get exact version information is to use the "Xamarin Studio" menu, "About Xamarin Studio" item, "Show Details" button and copy/paste the version informations (you can use the "Copy Information" button).
Comment 2 ostapdemkiv 2016-10-27 13:11:47 UTC
Vincent Dondain, thank you for testing so fast!
It is working good the way you described. It is Not working ONLY if first request after  
application launch was offline. I know it sounds strange, but it is reproducing on our Xamarin.iOs, Android and Mac apps.

=== Xamarin Studio Community ===

Version 6.1.1 (build 15)
Installation UUID: 7561d134-f95f-4234-9142-ab7d13a20ffe
Runtime:
	Mono 4.6.1 (mono-4.6.0-branch-c8sr0/ef43c15) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 406010005
=== Xamarin.iOS ===

Version: 10.0.1.10 (Xamarin Studio Community)
Hash: ad1cd42
Branch: cycle8-sr0-xi
Build date: 2016-10-03 15:18:44-0400

=== Xamarin.Mac ===

Version: 2.10.0.105 (Xamarin Studio Community)

=== Build Information ===

Release ID: 601010015
Git revision: fa52f02641726146e2589ed86ec4097fbe101888
Build date: 2016-09-22 08:03:02-04
Xamarin addins: 75d65712af93d54dc39ae4c42b21dfa574859fd6
Build lane: monodevelop-lion-cycle8-sr0

=== Operating System ===

Mac OS X 10.12.0
Darwin Ostaps-MacBook-Pro.local 16.0.0 Darwin Kernel Version 16.0.0
    Mon Aug 29 17:56:20 PDT 2016
    root:xnu-3789.1.32~3/RELEASE_X86_64 x86_64
Comment 3 Vincent Dondain [MSFT] 2016-10-27 15:18:41 UTC
Ah indeed I see what you mean, that for the precisions, I did not follow your repro steps careful enough (;

If you launch the app, disable the network right away and click on the button to action the above code, even if you restore the network you'll always get this "Exception: System.Net.WebException: Error: NameResolutionFailure"

Here's a test case for other team members: https://www.dropbox.com/s/onlcxu43usr248y/Bug45927.zip?dl=0