Ex *_*nta 10 c# exception system.configuration .net-assembly
我正在使用app.config文件来存储凭据,当我尝试检索它们时,我得到TypeLoadException如下:
无法从程序集'System.Configuration,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'加载类型'System.Configuration.DictionarySectionHandler'
这是一个.NET 4.5项目,我设置System和System.Configuration Copy-Local属性true,我不明白问题的来源.我对.NET编程没有经验,所以对汇编的概念不太满意.
以下是代码片段:
的app.config
<configSections>
<sectionGroup name="Credentials">
<section name="Twitter" type="System.Configuration.DictionarySectionHandler"/>
</sectionGroup>
</configSections>
<Credentials>
<Twitter>
<add key="****" value="*****"/>
<add key="****" value="*****"/>
</Twitter>
</Credentials>
Run Code Online (Sandbox Code Playgroud)
连接服务文件
var hashtable = (Hashtable)ConfigurationManager.GetSection("Credentials/Twitter");
Run Code Online (Sandbox Code Playgroud)
我知道这是一个常见的问题,我在发布之前用Google搜索了它.但到目前为止我发现的所有解决方案似乎都不起作用,或者我可能没有正确理解它们.
先感谢您.
参考msdn 文档,您需要按照 Hans 所说Fully qualified class name使用。app.config在你的代码中它将是
<sectionGroup name="Credentials">
<section name="Twitter" type="System.Configuration.DictionarySectionHandler, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</sectionGroup>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2436 次 |
| 最近记录: |