Bug 35037 - SystemConfiguration.NetworkReachability returns incorrect result
Summary: SystemConfiguration.NetworkReachability returns incorrect result
Status: RESOLVED ANSWERED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 9.0 (iOS9)
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-10-19 09:09 UTC by chris
Modified: 2016-04-12 15:04 UTC (History)
7 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test Solution (15.84 KB, application/x-zip-compressed)
2015-10-19 09:10 UTC, chris
Details
Sample Project (26.97 KB, application/zip)
2015-10-28 18:59 UTC, John Miller [MSFT]
Details


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:
Status:
RESOLVED ANSWERED

Description chris 2015-10-19 09:09:22 UTC
Hi,

Calling 'GetFlags' on NetworkReachability always returns 'Reachable' even if the domain doesn't exist. I'll attach a full test solution but the following code should result in "Failed..." but results in "Success = True".

The code is based on the Reachability sample.

string host = "nonsense.test12345679.com"; 
using (var r = new SystemConfiguration.NetworkReachability (host)) {
	NetworkReachabilityFlags flags;

	try {
		var returnvalue = r.GetFlags (out flags);
		string test = "";
	} catch (Exception ex) {
		_label.Text = "Error: " + ex.Message;
	}

	if (r.TryGetFlags (out flags)) {
		_label.Text = "Success = " + IsReachableWithoutRequiringConnection (flags);
	} else {
		_label.Text = "Failed to get flags ";
	}
}

If you switch the device into airplane mode then reachability is correctly returned as false.

I'm testing on an iPad Air, iOS 9.0.2 and the latest stable Xamarin.

Xamarin Studio
Version 5.9.7 (build 22)
Installation UUID: 7f359b26-2773-4d30-8dbf-b5b47e7ad099
Runtime:
	Mono 4.0.4 ((detached/d481017)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400040004

Xamarin.Android
Version: 5.1.7.12 (Business Edition)
Android SDK: /Users/chriskoiak/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

Xamarin Android Player
Version: Unknown version
Location: /Applications/Xamarin Android Player.app

Apple Developer Tools
Xcode 7.0.1 (8228)
Build 7A1001

Xamarin.iOS
Version: 9.0.1.29 (Business Edition)
Hash: 1d27ac2
Branch: master
Build date: 2015-09-25 18:08:44-0400

Xamarin.Mac
Version: 2.0.2.111 (Starter Edition)

Build Information
Release ID: 509070022
Git revision: 6bd1f169df44ca96addf8a035316c535a4fa46fa
Build date: 2015-09-30 12:30:15-04
Xamarin addins: 1c3e5c0859bdfec0ecd481a57ad6c03bc22f5536

Operating System
Mac OS X 10.11.0
Comment 1 chris 2015-10-19 09:10:04 UTC
Created attachment 13433 [details]
Test Solution
Comment 2 chris 2015-10-19 09:17:40 UTC
I've also tested on the latest Alpha channel but get the issues. 

Xamarin.iOS
Version: 9.2.0.84
Comment 3 John Miller [MSFT] 2015-10-28 14:27:24 UTC
I've also noticed a difference in the results by just running on an iOS 8.4 simulator.
Comment 4 John Miller [MSFT] 2015-10-28 18:59:29 UTC
Created attachment 13567 [details]
Sample Project

Per my last comment, use this project to reproduce. 

1. Run it on iOS 9 simulator.
2. Press the button.
3. Observe output logs
4. Repeat step 2 while not connected to the internet. 

1. Run it on iOS 8 simulator
2. Press the button.
3. Observe output logs
4. Repeat step 2 while not connected to the internet. 


On iOS 8, the flags return false when you _are_ connected to the web, but true when you are not. 
On iOS 9, the flats return true when you _are_ connected to the web, but false when you are not (expected).
Comment 5 Kent Green [MSFT] 2015-10-28 19:37:04 UTC
I was able to confirm the observations in Comment 4. 

## Build Information
=== Xamarin Studio ===

Version 5.9.7 (build 22)
Installation UUID: 8ef63a7c-1b18-40de-a334-7f78777fcb55
Runtime:
	Mono 4.0.4 ((detached/d481017)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400040004

=== Apple Developer Tools ===

Xcode 7.0.1 (8228)
Build 7A1001

=== Xamarin.iOS ===

Version: 9.0.1.29 (Business Edition)
Hash: 1d27ac2
Branch: master
Build date: 2015-09-25 18:08:44-0400

=== Xamarin.Android ===

Version: 5.1.7.12 (Business Edition)
Android SDK: /Users/kentgreen/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
		6.0    (API level 23)
Java SDK: /usr
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 2.0.2.111 (Business Edition)

=== Build Information ===

Release ID: 509070022
Git revision: 6bd1f169df44ca96addf8a035316c535a4fa46fa
Build date: 2015-09-30 12:30:15-04
Xamarin addins: 1c3e5c0859bdfec0ecd481a57ad6c03bc22f5536

=== Operating System ===

Mac OS X 10.10.5
Darwin Kents-Macbook-Pro.local 14.5.0 Darwin Kernel Version 14.5.0
    Wed Jul 29 02:26:53 PDT 2015
    root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64

Marking as CONFIRMED.
Comment 6 Miguel de Icaza [MSFT] 2015-11-25 15:53:52 UTC
This binding is merely a pass-through to the underlying operating system, so this is likely a change in the way the API works on Apple platforms, not a bug in the binding itself.
Comment 7 Sebastien Pouliot 2016-04-12 15:04:09 UTC
As stated in comment #6 this is not an issue with Xamarin.iOS. Different versions of iOS can return different values and our bindings are simply the OS values.