Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeLoadException

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.

like image 878
Ex Menta Avatar asked Feb 17 '14 10:02

Ex Menta


1 Answers

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>
like image 71
Jaroslav Kadlec Avatar answered Oct 16 '22 04:10

Jaroslav Kadlec