c# – ConfigurationManager.GetSection返回null

前端之家收集整理的这篇文章主要介绍了c# – ConfigurationManager.GetSection返回null前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的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");
}

@L_301_1@

原文链接:https://www.f2er.com/csharp/96967.html

猜你在找的C#相关文章