c# - 告诉 ConfigurationManager 忽略 App.config 部分

标签 c# app-config

我的 App.config 文件标记为:

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

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

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

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

我是否可以告诉 ConfigurationManager 忽略这个“Ignored”部分?

最佳答案

您可以将以下内容添加到您的 <configSections>元素:

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

关于c# - 告诉 ConfigurationManager 忽略 App.config 部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22714987/

相关文章:

c# - MVC架构中模型/业务层/数据访问和存储库之间有什么区别?

c# - QUICKFIX 64-bit Build for .NET on Visual Studio (.NET C++ DLL Wrapper)

c# - Selenium WebDriver C# - 获取文本

c# - 为什么我有时有一个 app.config 而有时有一个 binaryname.dll.config 文件?

c# - app.config 不保存我的配置

.net - 如何更改 App.config 重命名的内容?

c# - 出现错误 : Background. png 不是具有所需大小的有效 PNG 文件

c# - Azure 函数-System.Net.Http

windows-services - ConfigurationErrorsException : Unable to load type . .. 因为它不是公开的

windows-services - 有没有办法在 app.config 文件中指定服务名称?