我正在尝试为.net 4.0项目设置configSection。
<configuration>
<configSections>
<section name="MonitorFldrSection"
type="System.Configuration.NameValueFileSectionHandler, System, Version=4.0.0.0"
allowLocation="true"
allowDefinition="Everywhere"/>
</configSections>
<MonitorFldrSection>
<add name="fldr1" value="C:\Temp" />
<add name="fldr2" value="C:\Projects" />
</MonitorFldrSection>
<connectionStrings>
</connectionStrings>
<appSettings>
</appSettings>
</configuration>但是,当我尝试添加一个键时,我得到的所有提示都是注释或CDATA提示
当我尝试在代码中访问时
object obj = ConfigurationManager.GetSection("MonitorFldrSection");我收到此错误:{“为系统创建配置节处理程序时出错:无法加载文件或程序集‘(C:\Projects_4.0\NasImageIndexer\TestForm\bin\Debug\TestForm.exe.Config,Version=4.0.0.0’或其依赖项之一。系统找不到指定的文件。第5行)”}
除了NameValueFileSectionHandler,我还尝试过AppSettingsSection和DictionarySectionHandler。
我做错了什么?
发布于 2012-03-27 22:34:52
您能在位置C:\Projects_4.0\NasImageIndexer\TestForm\bin\Debug\TestForm.exe.Config?中找到此文件吗
如果没有,请更改配置文件Build Action - Content Copy to Output Directory - Copy Always的属性
编辑:
在添加公钥标记并将名称更改为key后,这对我很有效
<configuration>
<configSections>
<section name="MonitorFldrSection"
type="System.Configuration.NameValueFileSectionHandler, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowLocation="true"
allowDefinition="Everywhere"/>
</configSections>
<MonitorFldrSection>
<add key="fldr1" value="C:\Temp" />
<add key="fldr2" value="C:\Projects" />
</MonitorFldrSection>
<connectionStrings>
</connectionStrings>
<appSettings>
</appSettings>
</configuration>https://stackoverflow.com/questions/9891635
复制相似问题