【问题标题】:Tell ConfigurationManager to ignore App.config section告诉 ConfigurationManager 忽略 App.config 部分
【发布时间】:2014-03-28 14:01:06
【问题描述】:

我的 App.config 文件标记为:

<configuration>
    <configSections>
        <section name="Custom" type="…" />
    </configSections>
    <Custom>
        ...
    </Custom>
    <Ignored>
        ...
    </Ignored>
</configuration>

所以,我有一个配置文件,其中:

  • 一个部分(“自定义”)由 API 处理,我为它编写了 ConfigurationSection 继承器
  • 第二部分(“忽略”)我将自己解析,因为配置 API 不能让我解决我的任务。

当我运行程序时,出现异常“无法识别的配置部分'忽略'”。

我是否有可能告诉 ConfigurationManager 忽略此“已忽略”部分?

【问题讨论】:

  • 写入另一个xml文件
  • 我不认为你可以 ConfigManager 忽略它。其他替代方法是使用 xml 或资源文件来携带信息
  • 在另一个 xml 文件中写入配置块 - 这是显而易见的决定,但我不想产生大量的配置类型。我想在 App.config 中只定义一个统一配置,但使用不同类型的内部读取器 - 已知部分的默认 ConfigurationManager 和我的部分的自定义管理器。

标签: c# app-config


【解决方案1】:

您可以将以下内容添加到您的 &lt;configSections&gt; 元素中:

<section name="Ignored" type="System.Configuration.IgnoreSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

【讨论】:

  • 谢谢!我在发布问题后一两天找到了确切的解决方案。
猜你喜欢
  • 2019-06-27
  • 2011-06-20
  • 2018-07-16
  • 1970-01-01
  • 2010-10-09
  • 1970-01-01
  • 2018-10-07
  • 1970-01-01
  • 2011-05-09
相关资源
最近更新 更多