I am using the app.config file to store credentials and when I try to retrieve them, I get a TypeLoadException
as follows :
Could not load type 'System.Configuration.DictionarySectionHandler' from assembly 'System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
It's a .NET 4.5 project, I set the System
and System.Configuration
Copy-Local
attributes to true
, and I don't understand where the problem comes from. I'm not experienced in .NET programming, so not very at ease with the concept of assembly.
Here are the snippets of code :
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>
Connecting service file
var hashtable = (Hashtable)ConfigurationManager.GetSection("Credentials/Twitter");
I know it is a common issue, and I googled it before posting. But all the solutions I've found so far don't seem to work, or I may not have understood them correctly.
Thank you in advance.
With reference to msdn documentation you need to use Fully qualified class name
in app.config
as Hans said. In your code it would be
<sectionGroup name="Credentials">
<section name="Twitter" type="System.Configuration.DictionarySectionHandler, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</sectionGroup>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With