【问题标题】:configurationmanager exception on server but does work on dev machine服务器上的配置管理器异常,但在开发机器上工作
【发布时间】:2018-02-09 22:31:44
【问题描述】:

这个问题困扰了我好几个小时。
我有一个 LINQ 查询来解析我的应用程序的配置文件中未定义数量的电子邮件地址。
以下代码将有助于 tp 理解:

App.config
<configuration>
  <appSettings>
    <add key="errorMail1" value="support@mail.com"/>
    <add key="errorMail2" value="test@mail.com"/>
  </appSettings>
<configuration>

因此,当我阅读电子邮件地址时,我通过属性按以下方式进行操作:

private List<string> _mailsWhenProblems;
public List<string> mailsWhenProblems
{
    get
    {
        if (_mailsWhenProblems == null)
        {
            var keys = ConfigurationManager.AppSettings.Keys;
            _mailsWhenProblems = keys.Cast<object>()
                .Where(key => key.ToString().ToLower()
                .Contains("errorMail".ToLower()))
                .Select(key => ConfigurationManager.AppSettings.Get(key.ToString())).ToList();
        }
        return _mailsWhenProblems;
    }
    set
    {
        _mailsWhenProblems = value;
    }
}

也就是说,只要我在开发机器上以调试模式运行它,一切都会按预期完美运行。但是一旦我在 Windows Server 2012 上部署它,应用程序就会崩溃并出现以下异常:

************** Texte de l'exception **************
System.Configuration.ConfigurationErrorsException: Échec de l'initialisation du système de configuration ---> System.Configuration.ConfigurationErrorsException: Section de configuration non reconnue oracle.manageddataaccess.client. (C:\Program Files\celibec\Celibec Transfert Android FileWatcher\FileWatcherService.exe.Config line 20)
   à System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
   à System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
   à System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
   --- Fin de la trace de la pile d'exception interne ---
   à System.Configuration.ConfigurationManager.PrepareConfigSystem()
   à System.Configuration.ConfigurationManager.get_AppSettings()

【问题讨论】:

  • 不知何故,该配置文件中存在 oracle.manageddataaccess.client 设置,我敢打赌 Windows 服务器上未安装 ODP.Net。要么安装它,要么从配置中删除 oracle 数据客户端部分。
  • 非常有针对性!谢谢!

标签: c# production-environment configurationmanager


【解决方案1】:

异常与您的代码无关。您可能忘记了服务器配置文件中的&lt;configSections&gt; 标签。使用此标签,您可以注册自定义 oracle.manageddataaccess.client 标签。我猜你的开发机器上有这个标签。
请注意,&lt;configSections&gt; 必须是 &lt;configuration&gt; 标记中的第一个。

有关更多信息,请参阅有关 Custom Configuration Sections 的 MSDN 链接。

【讨论】:

    猜你喜欢
    • 2011-05-30
    • 1970-01-01
    • 2011-03-02
    • 1970-01-01
    • 2017-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多