需要注意的是在获取配置的SectionName的时候所使用的名称必须是配置文件根节点的名称
比如在app.config 配置的:
<
configurationSections
>
< configurationSection name ="SystemConfiguration" encrypt ="false" >
< storageProvider xsi:type ="XmlFileStorageProviderData" name ="XML File Storage Provider" path ="AppSettings.config" />
< dataTransformer xsi:type ="XmlSerializerTransformerData" name ="Xml Serializer Transformer" >
< includeTypes />
</ dataTransformer >
</ configurationSection >
< configurationSection name ="SystemConfiguration" encrypt ="false" >
< storageProvider xsi:type ="XmlFileStorageProviderData" name ="XML File Storage Provider" path ="AppSettings.config" />
< dataTransformer xsi:type ="XmlSerializerTransformerData" name ="Xml Serializer Transformer" >
< includeTypes />
</ dataTransformer >
</ configurationSection >
其中带下划线的就是配置的SectionName,这个名称必须要与保存配置的文件里的根节点一致如:
<?
xml version="1.0" encoding="utf-8"
?>
< SystemConfiguration >
< xmlSerializerSection type ="LSA.Model.Configuration.AppSettings, LSA.Model, Version=1.0.2133.17570, Culture=neutral, PublicKeyToken=null" >
< LSA .AppSettings xmlns:xsd ="http://www.w3.org/2001/XMLSchema" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" xmlns ="http://www.sundun.cn/LSAPro/10-27-2005/data" >
< SysConfig >
< SystemConfiguration >
< xmlSerializerSection type ="LSA.Model.Configuration.AppSettings, LSA.Model, Version=1.0.2133.17570, Culture=neutral, PublicKeyToken=null" >
< LSA .AppSettings xmlns:xsd ="http://www.w3.org/2001/XMLSchema" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" xmlns ="http://www.sundun.cn/LSAPro/10-27-2005/data" >
< SysConfig >
如果在平时使用中改了SectionName的名称,那么记得把两个地方都改过来,这个问题搞了我好一阵子。