使用ConfigurationManager.GetSection出错:
出错语句:
Hashtable ht = new Hashtable();
ht = (Hashtable)ConfigurationManager.GetSection("IsLine.AppLog.Configuration/OracleUsingSPRender");
textBox1.Text = ht["AppenderStyle"].ToString();
错误信息:
创建 IsLine.AppLog.Configuration/OracleUsingSPRender 的配置节处理程序时出错: 未能从程序集“System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”中加载类型“IsLine.Data.Configuration.SuitConfig”。
说明:
IsLine.AppLog.Configuration/OracleUsingSPRender 是app.config中的一个节点:
<sectionGroup name="
IsLine.AppLog.Configuration">
<section name="
OracleUsingSPRender" type="
IsLine.Data.Configuration.SuitConfig"/>
</sectionGroup>
<IsLine.AppLog.Configuration>
<OracleUsingSPRender>
<AppenderStyle>Oracle</AppenderStyle>
<AppenderType>StoredProcedure</AppenderType>
<AppenderInf>IsLine.Data.Configuration.OracleConnectString</AppenderInf>
<AppenderContent>SP_ADD_ILFWLOG.ADD_ILFWLOG</AppenderContent>
<LayoutInf></LayoutInf>
<Level>Debug</Level>
</OracleUsingSPRender>
</IsLine.AppLog.Configuration>
IsLine.Data.Configuration.SuitConfig :
namespace IsLine.Data.Configuration
{
public class SuitConfig : IConfigurationSectionHandler
{
object IConfigurationSectionHandler.Create(object parent, object configContext, System.Xml.XmlNode section)
{
Hashtable table = new Hashtable();
foreach (XmlNode xnl in section.ChildNodes)
{
if (xnl.NodeType == XmlNodeType.Element)
{
table.Add(xnl.Name, xnl.InnerText);
}
}
return table;
}
}
}
IsLine.AppLog.Configuration/OracleUsingSPRender运行时会交给IsLine.Data.Configuration.SuitConfig 处理,并返回给ConfigurationManager.GetSection一个Hashtable 。这种用法在B/S中没问题,在C/S中就报错,不知为啥?