Bug 12038 - Subscribing to System.Net.NetworkInformation throws EntryPointNotFoundException from System.Net.NetworkInformation.NetworkChange
Summary: Subscribing to System.Net.NetworkInformation throws EntryPointNotFoundExcepti...
Status: RESOLVED FIXED
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: 1.2.x
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-04-30 03:41 UTC by ian
Modified: 2015-01-19 19:46 UTC (History)
3 users (show)

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


Attachments
Test Case (1.56 KB, application/zip)
2013-04-30 11:25 UTC, ian
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 FIXED

Description ian 2013-04-30 03:41:04 UTC
We're trying to add cross-platform network availability awareness. 
It's simple with .Net -> subscribe to the standard NetworkAvailabilityChanged event. 
In Mono, on OSX we immeadiately get an error. 
Could you tell us the problem and when we might hope to get it fixed?

Failing TestCase:

using NUnit.Framework;
using System.Net.NetworkInformation;
using System.Runtime.CompilerServices;

namespace NetworkAvailabilityTest
{
	[TestFixture()]
	public class Test
	{
		int WasOnNetworkAddressChangedCalled;
		int WasOnNetworkAvailabilityChangedCalled;
		void OnNetworkAddressChanged (object sender, EventArgs e)
		{
			WasOnNetworkAddressChangedCalled++;
		}
		void OnNetworkAvailabilityChanged (object sender, NetworkAvailabilityEventArgs e)
		{
			WasOnNetworkAvailabilityChangedCalled++;
		}
		
		[SetUp]
		public void TestSetup()
		{
			NetworkChange.NetworkAvailabilityChanged += OnNetworkAvailabilityChanged;
			NetworkChange.NetworkAddressChanged += OnNetworkAddressChanged;
		}
		[Test()]
		public void TestCase ()
		{
			Assert.True (); //fails in setup - EntryPointNotFoundException in System.Net.NetworkInformation.NetworkChange:CreateNLSocket
		}
		[TestFixtureTearDown]
		public void TestDown()
		{
			NetworkChange.NetworkAvailabilityChanged -= OnNetworkAvailabilityChanged;
			NetworkChange.NetworkAddressChanged -= OnNetworkAddressChanged;
		}
	}
}
Comment 1 ian 2013-04-30 04:05:40 UTC
Call Stack:
/29/2013 16:17:43.507 [1] ERROR AppDelegate.FinishedLaunching - Unexpected error: System.EntryPointNotFoundException: CreateNLSocket
  at (wrapper managed-to-native) System.Net.NetworkInformation.NetworkChange:CreateNLSocket ()
  at System.Net.NetworkInformation.NetworkChange.EnsureSocket () [0x00021] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-3.0.6/_build/mono-3.0.6.git/mcs/class/System/System.Net.NetworkInformation/NetworkChange.cs:71 
  at System.Net.NetworkInformation.NetworkChange.Register (System.Net.NetworkInformation.NetworkAvailabilityChangedEventHandler d) [0x00000] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-3.0.6/_build/mono-3.0.6.git/mcs/class/System/System.Net.NetworkInformation/NetworkChange.cs:165 
  at System.Net.NetworkInformation.NetworkChange.add_NetworkAvailabilityChanged (System.Net.NetworkInformation.NetworkAvailabilityChangedEventHandler value) [0x00000] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-3.0.6/_build/mono-3.0.6.git/mcs/class/System/System.Net.NetworkInformation/NetworkChange.cs:60 (NetworkAvailabilityTest.Test.TestCase)
Comment 2 Aaron Bockover [MSFT] 2013-04-30 11:07:53 UTC
Are you linking the application? (Project Options->Mac OS X Packaging->[X] Include the Mono runtime in the application bundle->Linker Behavior: Link All)
Comment 3 Aaron Bockover [MSFT] 2013-04-30 11:13:24 UTC
I am not able to reproduce that exception in either linked or unlinked mode. Can you please derive a test sample that can be compiled without inferring your test harness or environment? Also, which version of Mono are you using? Would you paste the version information from the "Show Details" view in the "About Xamarin Studio" dialog?

Thanks!
Comment 5 ian 2013-04-30 11:25:31 UTC
Created attachment 3897 [details]
Test Case

TEST CASE
Comment 6 Aaron Bockover [MSFT] 2013-04-30 13:18:18 UTC
Running this test does not produce any exceptions.

The exception your are getting indicates that underlying code in the stack is missing entirely. Specifically CreateNLSocket is a native function that exists in the native library MonoPosixHelper [1], and is PInvoked by the NetworkChange class [2].

It's likely that MonoPosixHelper is not able to be found, and thus the native functions cannot be invoked. I'm not sure how you're using Mono, so it's hard to diagnose.

Can you set MONO_LOG_LEVEL=debug in your environment and paste the output?

[1] /Library/Frameworks/Mono.framework/Versions/Current/lib/libMonoPosixHelper.{a,dylib}
[2] https://github.com/mono/mono/blob/master/mcs/class/System/System.Net.NetworkInformation/NetworkChange.cs#L185
Comment 7 ian 2013-05-01 03:20:33 UTC
Hi Aaron, 

Thanks a lot for your response!

Well I haven't done anything unusual - I simply install Mono by executing the dmg for 3.0.6 (I think I'm using the MRE installer). 

I guess you aren't experiencing problems due to the internals NICs/Ethernet/Bluetooth configuration is different to mine. 

I set the above statement in a terminal window and re-ran the test in Xamarin Studio (I'm not sure that's what you had in mind) - and the identical test output is produced.

I don't understand the 2 links at the bottom of your post... please give guidance as it seems this should be working out of the box....
Comment 8 ian 2013-05-01 03:40:47 UTC
So ... running the test under Mono 2.0.11 runs and green. If you run it under 3.0.6 it errors as above.

Is there a change in 3.0.6 at all for this? Is there a command I can issue?
Comment 9 ian 2013-05-01 03:46:42 UTC
Ok We've verified it's ok in 3.0.10 but now we have an issue - we cannot upgrade to 3.0.10 as there's an outstanding bug that prevents us building Mono on the Command Line. 

This is a blocker. Will this be fixed soon ? Otherwise we're rather stuck...
Comment 10 ian 2013-05-01 05:28:04 UTC
Ok We've verified it's ok in 3.0.10 but now we have an issue - we cannot upgrade to 3.0.10 as there's an outstanding bug that prevents us building Mono on the Command Line. 

This is a blocker. Will this be fixed soon ? Otherwise we're rather stuck...
Comment 11 Aaron Bockover [MSFT] 2013-05-01 13:11:18 UTC
As of right now Xamarin.Mac is not supported on 3.0.x. It will be soon, but I am not sure exactly when.
Comment 12 Aaron Bockover [MSFT] 2013-05-01 17:52:40 UTC
As a forewarning: earlier today I looked at the implementation of NetworkChange and saw that it is only actually supported under Linux. On other platforms the events will never be raised, so it is currently effectively useless. So unfortunately even though you ran into the exception on Mono 3.0.x, the API wouldn't have worked as advertised on the Mac.

I've done two things that will land in the future:

1. I've made the SCNetworkReachability API accessible in Xamarin.Mac. This is currently committed on our master branch and will be included in the next release of Xamarin.Mac. [1]

2. I've implemented System.Net.NetworkInformation.NetworkChange support for Mac OS X using SCNetworkReachability API. This is currently pending a land on the core mono branches. I will update this bug when it has landed. [2]

This means that going forward, you will be free to use either APIs (the BCL API or the OS X API). The OS X API is a little more expressive while the BCL API only exposes "a network is available".

When using both APIs, there is an underlying requirement that a CFMainLoop on the subscribing thread be running, as this is how availability messages are dispatched by the OS.

[1] https://developer.apple.com/library/mac/#documentation/SystemConfiguration/Reference/SCNetworkReachabilityRef/Reference/reference.html

[2] https://github.com/mono/mono/pull/627
Comment 13 Aaron Bockover [MSFT] 2013-05-01 18:17:31 UTC
The patch for Mono itself has been merged into master.
Comment 14 ian 2013-05-02 07:22:25 UTC
Hi Aaron. 

That's a shame. I wish we knew yesterday....
... in the meantime is there any timescale for the next Xam/Mac release? We're rather reliant on it now.

Also this is the fourth or fifth issue where we've encountered a MONO API that is not implemented on OSX.

Is there a list - anywhere - of any further such issues? Otherwise it's impossible for us to plan our development tasks as we are repeatedly hit by runtime messages that result in us needing a subsequent Xam.Mac release. 

Thanks again Aaron.
Comment 15 Miguel de Icaza [MSFT] 2013-05-02 11:51:45 UTC
Hello Ian,

This tool should give you a good enough overview of what is available on Mono:

http://www.mono-project.com/MoMA
Comment 16 Timothy Risi 2015-01-19 19:46:04 UTC
Sample test passes successfully