From e6b8be8cbaf7c91f1dbca0dd3c56622f4b652a31 Mon Sep 17 00:00:00 2001 From: Jonathan Shore Date: Sat, 16 Mar 2013 11:34:59 -0400 Subject: [PATCH] minor fix for bug 9520: - socket configuration attempts to determine if system supports ipv6 - checks app configuration, but configuration throws exception if called from embedded context - solution is to put a try/catch guard and fall to an alternative test for ipv6 --- .../System/System.Net.Sockets/Socket_2_1.cs | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/mcs/class/System/System.Net.Sockets/Socket_2_1.cs b/mcs/class/System/System.Net.Sockets/Socket_2_1.cs index 05b1ff31f54e4..11a7eda8a45ee 100644 --- a/mcs/class/System/System.Net.Sockets/Socket_2_1.cs +++ b/mcs/class/System/System.Net.Sockets/Socket_2_1.cs @@ -752,16 +752,33 @@ internal static void CheckProtocolSupport () } 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) {