Bug 4631 - NetworkInterface.GetAllNetworkInterfaces fails
Summary: NetworkInterface.GetAllNetworkInterfaces fails
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.2
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
Depends on:
Reported: 2012-04-24 20:20 UTC by Michael Bayne
Modified: 2012-04-25 20:21 UTC (History)
4 users (show)

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

Reproducing project (3.99 KB, application/x-gzip)
2012-04-25 11:31 UTC, Michael Bayne
updated System.dll assembly (1.04 MB, application/octet-stream)
2012-04-25 19:35 UTC, Sebastien Pouliot

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 Michael Bayne 2012-04-24 20:20:59 UTC
As of Monotouch 5.2.11 NetworkInterface.GetAllNetworkInterfaces now fails with SYstem.ArgumentException (with message "length") when run in the simulator.

I'd paste in the stack trace, but I can't figure out how to copy it out of the "helpful" dialog that MonoDevelop insists on wrapping exceptions in, instead of just writing them out to the console.

Anyway, this worked before this last flurry of Mono/MonoTouch/MonoDevelop updates.
Comment 1 Rolf Bjarne Kvinge [MSFT] 2012-04-25 06:35:15 UTC
I tried to do this in a sample project:

Console.WriteLine (NetworkInterface.GetAllNetworkInterfaces ());

and it doesn't crash for me, so it looks like the issue is a bit more complex. Can you create a test case that fails for you? You should also be able to print the stack trace to the application output like this:

try {
    NetworkInterface.GetAllNetworkInterfaces ();
} catch (Exception ex) {
    Console.WriteLine (ex);
Comment 2 Sebastien Pouliot 2012-04-25 09:35:06 UTC
It could be something specific to your Mac networking that Mono cannot parse correctly.

Can you attach your SPX (mark it private) so we can see all your network settings ?

Go to the "Mac Menu",
Select "About this Mac"
Click on "More Info..."
then from the System Profiler app do a File | Save As...
and attach the file to the bug report.
Comment 4 Michael Bayne 2012-04-25 11:31:55 UTC
Created attachment 1746 [details]
Reproducing project
Comment 5 Michael Bayne 2012-04-25 11:32:04 UTC
SPX attached, and a simple project that demonstrates the bug. And here's the stack trace:

System.ArgumentException: length
  at System.Array.Copy (System.Array sourceArray, Int32 sourceIndex, System.Array destinationArray, Int32 destinationIndex, Int32 length) [0x000ab] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Array.cs:967 
  at System.Net.NetworkInformation.MacOsNetworkInterface.ImplGetAllNetworkInterfaces () [0x00148] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net.NetworkInformation/NetworkInterface.cs:472 
  at System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces () [0x00014] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net.NetworkInformation/NetworkInterface.cs:58 

Apologies for the snark about the dialog, clearly it's not that hard to capture it myself and log it. It was a long day. :)
Comment 7 Gonzalo Paniagua Javier 2012-04-25 17:07:58 UTC
Perhaps 5.2 does not have JonP's 9a8c51583ea487b6ce6ebc895176de04d5cc2386?

Looks like this has already been fixed.
Comment 8 Sebastien Pouliot 2012-04-25 19:25:18 UTC
Great catch Gonzalo!

Michael since you're on 5.2.11 I can give you an updated System.dll to test the fix. Interested ?
Comment 9 Michael Bayne 2012-04-25 19:28:31 UTC
Not sure if my email reply went anywhere useful, but I'd definitely be happy to test the fixed System.dll.
Comment 10 Sebastien Pouliot 2012-04-25 19:35:10 UTC
Created attachment 1747 [details]
updated System.dll assembly

To use the attached assembly (on top of MonoTouch 5.2.11) do:

1) backup your /Developer/MonoTouch/usr/lib/mono/2.1/System.dll and /Developer/MonoTouch/usr/lib/mono/2.1/System.dll.mdb files

2) copy the attached file to /Developer/MonoTouch/usr/lib/mono/2.1/System.dll

3) remove the /Developer/MonoTouch/usr/lib/mono/2.1/System.dll.mdb symbols (they won't match anymore)

4) clean, rebuild and test your application

5) let us know the outcome!
Comment 11 Michael Bayne 2012-04-25 19:39:44 UTC
Works great! Thanks.
Comment 12 Sebastien Pouliot 2012-04-25 20:21:28 UTC
Great! Keep this assembly until we release 5.2.12 :-)

5.2-series: a3571af020c4ce02e35cdadfca4f5ff2861d184d
master: already fixed (Apr 5th)