11

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.

T.S.
  • 18,195
  • 11
  • 58
  • 78
Ex Menta
  • 113
  • 1
  • 5
  • 4
    The "type" attribute is malformed, it needs to be the fully qualified type name: "System.Configuration.DictionarySectionHandler, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" – Hans Passant Feb 17 '14 at 12:35
  • 1
    That is it ! I already tried that but I think I forgot one of the elements. Thank you very much ! – Ex Menta Feb 17 '14 at 12:38

1 Answers1

3

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>
Jaroslav Kadlec
  • 2,505
  • 4
  • 32
  • 43