C# 获取配置部分

C# 获取配置部分,c#,windows-services,app-config,configurationmanager,C#,Windows Services,App Config,Configurationmanager,我有一个桌面应用程序,我需要用它来测试我的windows服务 应用程序只需调用处理我的业务的windows服务类,首先它应该从app.config加载一些数据 应用程序配置在服务项目中,我将我的混淆存储在自定义节[ABCConfigurationSection]中。 像 主配置部分如 <configuration> <configSections> <section name="ABCConfigurationSection" type="ABCConf

我有一个桌面应用程序,我需要用它来测试我的windows服务

应用程序只需调用处理我的业务的windows服务类,首先它应该从app.config加载一些数据

应用程序配置在服务项目中,我将我的混淆存储在自定义节[ABCConfigurationSection]中。 像

主配置部分如

<configuration>
  <configSections>
    <section name="ABCConfigurationSection" type="ABCConfiguration, App.Core" />
  </configSections>
</configuration>
当我检索将ABCConfigurationSection作为节名传递的配置节时,我得到了null!
关于应用程序配置的结构是否在您的配置节中缺少某些内容,对于节ABCConfigurationSection,您可以声明称为ABCConfiguration的类型是处理您的节的类型

这意味着,在代码中,您应该定义一个名为ABCConfiguration的类,该类派生自读取您的节的ConfigurationSection


关于这个问题有很多细节。这是一个链接,指向提供完整示例的地方

能否显示代码、如何调用?section=System.Configuration.ConfigurationManager.GetSectionABCConfigurationSection作为App.Core.ABCConfiguration;我有这个类,我将它用于另一个应用程序——web应用程序——没有错误也没有问题。仅当在win服务中使用时出现的问题您可以检查配置文件的文件属性吗?。这是一个类似的问题:我不认为,我的文件属性与参考文章中的不一样!它不是只读的,即使没有取消阻止按钮也不会隐藏
<configuration>
  <configSections>
    <section name="ABCConfigurationSection" type="ABCConfiguration, App.Core" />
  </configSections>
</configuration>