Bug 13293 - Reachability: empty flags when calling TryGetFlags twice
Summary: Reachability: empty flags when calling TryGetFlags twice
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 6.2.x
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-07-17 10:47 UTC by Maxim
Modified: 2017-01-30 20:23 UTC (History)
2 users (show)

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 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.

Related Links:

Description Maxim 2013-07-17 10:47:15 UTC
I'd asked on StackOverflow and no one helped. So I replied to bug tracker:

I have this code to test network connection:

<!-- language: c# -->

			if (remoteHostReachability == null) {
				remoteHostReachability = new NetworkReachability (HostName);

				// Need to probe before we queue, or we wont get any meaningful values
				// this only happens when you create NetworkReachability from a hostname
				reachable = remoteHostReachability.TryGetFlags (out flags);
				//remoteHostReachability.SetCallback (OnChange);
				remoteHostReachability.SetNotification (OnChange);
				remoteHostReachability.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);
			} else {
                reachable = remoteHostReachability.TryGetFlags (out flags);

When calling it first time, flags are ok. But, when calling it second time, flags are always equals to **zero**. Tested on iOS Simulator 5.0.

What's the problem? In both [Apple][1]'s and [Xamarin][2]'s examples NetworkReachability created once.

  [1]: http://developer.apple.com/library/ios/#samplecode/Reachability/Listings/Classes_Reachability_m.html#//apple_ref/doc/uid/DTS40007324-Classes_Reachability_m-DontLinkElementID_6
  [2]: https://github.com/xamarin/monotouch-samples/blob/master/ReachabilitySample/reachability.cs
Comment 1 Vincent Dondain [MSFT] 2017-01-30 20:16:07 UTC
Hi Maxim,

I fail to understand your question. The samples seems to behave as expected.

"NetworkReachability remoteHostReachability" is only created once (singleton) and the "TryGetFlags" method called on it sets the flags to "Reachable" if the host is actually reachable.

I always get "Reachable" from "TryGetFlags ()" on "www.google.com" which is expected.

Not sure you're still having an issue with this but in any case if you provide more details on what's confusing to you I can certainly try to give it a precise answer.

This does not seem like a bug in Xamarin.iOS though as the template behaves correctly (and is identical to the Apple template).

For questions I'd recommend using our forums https://forums.xamarin.com/categories/ios or stack overflow: http://stackoverflow.com/questions/tagged/xamarin

In the meantime I'm closing this bug.

Comment 2 Maxim 2017-01-30 20:23:31 UTC
No problem. I'm 3.5 years out of Xamarin world :)
Hope company had procedure to solve old issues.