【发布时间】: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