Skip to content

Commit

Permalink
minor fix for bug 9520:
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
tr8dr committed Mar 16, 2013
1 parent efda0d4 commit e6b8be8
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions mcs/class/System/System.Net.Sockets/Socket_2_1.cs
Expand Up @@ -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) {
Expand Down

0 comments on commit e6b8be8

Please sign in to comment.