加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – ConfigurationManager.GetSection返回null

发布时间:2020-12-15 17:47:34 所属栏目:百科 来源:网络整理
导读:这是我的app.config configuration configSections section name="procedureList" type="System.Configuration.NameValueSectionHandler,System,Version=4.0.30319,Culture=neutral,PublicKeyToken=b77a5c561934e089"/ /configSections procedureList add ke
这是我的app.config
<configuration>
  <configSections>
      <section name="procedureList" type="System.Configuration.NameValueSectionHandler,System,Version=4.0.30319,Culture=neutral,PublicKeyToken=b77a5c561934e089"/>
  </configSections>

  <procedureList>
    <add key="NAS.spBusObjGetLineProd" value="@area='Melt Shop';@endDt=?date?;@dayonly=1;@obj='Melt Shop Business Objective" />
    <add key="NAS.spBusObjGetLineProd" value="@area='Cold Mill';@endDt=?date?;@dayonly=1;@obj='Cold Mill Business Objective" /> 
  </procedureList>
  <appSettings>
    <add key="Connstr" value=""/>
    <add key="Userid" value=""/>
    <add key="Timeout" value=""/>
  </appSettings>

</configuration>

但是当我在代码中调用它时,我得到一个null

public void samplemethod()
{
    NameValueCollection nvc = ConfigurationManager.GetSection("procedureList") as NameValueCollection;
    string[] keys = nvc.AllKeys;
}

我会感谢任何帮助指出我做错了什么

解决方法

Using section handlers to group settings in the configuration file

例如,您可以按照以下内容进行操作

private void ReadSettings()
{
    NameValueCollection loc = 
   (NameValueCollection )ConfigurationSettings.GetConfig("procedureList");
}

MSDN ConfigurationManager.GetConfig Method

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读