這裏是我的app.configConfigurationManager.GetSection返回null
<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;
}
我將不勝感激指出任何幫助我做了什麼錯
您對此投下了錯誤信息。我會在下面發佈一個示例以及可用作參考的鏈接 – MethodMan 2012-08-08 21:06:34
如果'as'投射操作失敗,則返回空值。但是,配置文件注意到節類型是'NameValueSectionHandler' - 您應該在調用GetSection()時轉換爲此類型。 – 2012-08-08 21:14:58
即使當我將類型更改爲NameValueSectionHandler時,我仍然得到空回 – edepperson 2012-08-08 21:17:22