Merge pull request #600 from tr8dr/master
authorRodrigo Kumpera <kumpera@gmail.com>
Sun, 21 Jul 2013 19:21:29 +0000 (12:21 -0700)
committerRodrigo Kumpera <kumpera@gmail.com>
Sun, 21 Jul 2013 19:21:29 +0000 (12:21 -0700)
Fix for bug 9250 (critical bug for embedded mono)

mcs/class/System/System.Net.Sockets/Socket_2_1.cs

index 05b1ff31f54e49d09bb893fcd86a6f893e35eb58..11a7eda8a45ee9b9ae8631201dcf2a76a9313f9a 100644 (file)
@@ -752,16 +752,33 @@ namespace System.Net.Sockets {
                        }
 
                        if (ipv6Supported == -1) {
+                               // We need to put a try/catch around ConfigurationManager methods as will always throw an exception 
+                               // when run in a mono embedded application.  This occurs as embedded applications do not have a setup
+                               // for application config.  The exception is not thrown when called from a normal .NET application. 
+                               //
+                               // We, then, need to guard calls to the ConfigurationManager.  If the config is not found or throws an
+                               // exception, will fall through to the existing Socket / API directly below in the code.
+                               //
+                               // Also note that catching ConfigurationErrorsException specifically would require library dependency
+                               // System.Configuration, and wanted to avoid that.
 #if !NET_2_1
 #if CONFIGURATION_DEP
-                               SettingsSection config;
-                               config = (SettingsSection) System.Configuration.ConfigurationManager.GetSection ("system.net/settings");
-                               if (config != null)
-                                       ipv6Supported = config.Ipv6.Enabled ? -1 : 0;
+                               try {
+                                       SettingsSection config;
+                                       config = (SettingsSection) System.Configuration.ConfigurationManager.GetSection ("system.net/settings");
+                                       if (config != null)
+                                               ipv6Supported = config.Ipv6.Enabled ? -1 : 0;
+                               } catch {
+                                       ipv6Supported = -1;
+                               }
 #else
-                               NetConfig config = System.Configuration.ConfigurationSettings.GetConfig("system.net/settings") as NetConfig;
-                               if (config != null)
-                                       ipv6Supported = config.ipv6Enabled ? -1 : 0;
+                               try {
+                                       NetConfig config = System.Configuration.ConfigurationSettings.GetConfig("system.net/settings") as NetConfig;
+                                       if (config != null)
+                                               ipv6Supported = config.ipv6Enabled ? -1 : 0;
+                               } catch {
+                                       ipv6Supported = -1;
+                               }
 #endif
 #endif
                                if (ipv6Supported != 0) {