gpt4 book ai didi

c# - ConfigurationManager.GetSection 返回 null

转载 作者:可可西里 更新时间:2023-11-01 08:11:02 25 4
gpt4 key购买 nike

这是我的 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>

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

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

关于c# - ConfigurationManager.GetSection 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11873151/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com