当前位置:编程学习 > C#/ASP.NET >>

configSections读取时报异常

配置一个configSections,在读取时报异常,代码如下

 Dictionary<string, string> _dic = ConfigurationManager.GetSection("sampleSection") as Dictionary<string, string>;

异常信息:创建 sampleSection 的配置节处理程序时出错: 未能从程序集“System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”中加载类型“ConfigSections.SingleTagSectionHandler”。 (E:\个人测试项目\ConfigSectionTest\ConfigSections\bin\Debug\ConfigSections.vshost.exe.Config line 5)
PS:已经引用:system.configuration.dll 异常 --------------------编程问答-------------------- 应该先读取配置文件,修改代码为:

var config = ConfigurationManager.OpenExeConfiguration(
    ConfigurationUserLevel.None);
var s = (TestConfigurationSection) config
    .GetSection("sampleSection ");
--------------------编程问答--------------------
引用 1 楼 lizhi3186575 的回复:
应该先读取配置文件,修改代码为:

var config = ConfigurationManager.OpenExeConfiguration(
    ConfigurationUserLevel.None);
var s = (TestConfigurationSection) config
    .GetSection("sampleSection ");
不好使...只是降低了权限限制,但问题依旧!3Q --------------------编程问答-------------------- 你搞得是app.config吧,换成web.config 应该就可以了。 --------------------编程问答-------------------- 你的配置文件呢? --------------------编程问答-------------------- 这个是MSDN上面的解释,实例也是webconfig,http://msdn.microsoft.com/zh-cn/library/2tw134k3(v=vs.100).aspx
好了,记得给分哦。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,