我正在使用 app.config 文件来存储凭据,当我尝试检索它们时,我得到TypeLoadException
如下:
无法从程序集“System.Configuration,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a”加载类型“System.Configuration.DictionarySectionHandler”
这是一个 .NET 4.5 项目,我将System
andSystem.Configuration
Copy-Local
属性设置为true
,但我不明白问题出在哪里。我没有 .NET 编程经验,因此对汇编的概念不太了解。
以下是代码片段:
应用程序配置
<configSections>
<sectionGroup name="Credentials">
<section name="Twitter" type="System.Configuration.DictionarySectionHandler"/>
</sectionGroup>
</configSections>
<Credentials>
<Twitter>
<add key="****" value="*****"/>
<add key="****" value="*****"/>
</Twitter>
</Credentials>
连接服务文件
var hashtable = (Hashtable)ConfigurationManager.GetSection("Credentials/Twitter");
我知道这是一个常见的问题,我在发布之前搜索了它。但是到目前为止我发现的所有解决方案似乎都不起作用,或者我可能没有正确理解它们。
先感谢您。