配置系统无法初始化异常

时间:2013-06-20 14:02:21

标签: c# .net exception dns

我有一小段代码如下:

  private string ResolveAddress(string domain)
  {
     try
     {
        if (Regex.IsMatch(domain, @"\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}"))
           return domain;
        else
           return Dns.GetHostAddresses(domain)[0].ToString();
     }
     catch (Exception ex)
     {
        Error.Record("Exception caught in ResolveAddress", ex);
        return domain;
     }
  }

今天,我第一次有人抱怨他们无法连接到我的主机。我查看他们的日志并看到以下异常:

# 6/20/2013 9:28:59 AM: Exception caught in ResolveAddress
Exception message: Configuration system failed to initialize
Exception stack trace:    at System.Configuration.ConfigurationManager.PrepareConfigSystem()
   at System.Configuration.ConfigurationManager.GetSection(String sectionName)
   at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
   at System.Net.Configuration.SettingsSectionInternal.get_Section()
   at System.Net.Sockets.Socket.InitializeSockets()
   at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)
   at System.Net.Dns.GetHostAddresses(String hostNameOrAddress)
   at NDTPresence.MainWindow.ResolveAddress(String domain)

显然,如果Dns.GetHostAddresses调用失败,他们将无法连接到我的服务。我的问题是为什么会发生这种情况?如果在用户的AppData / Roaming中,该主机名的配置文件即将出现,但是他们(我相信)为每个人安装了它。

感谢。

0 个答案:

没有答案