2

I've one problem which makes me crazy. I wanted to add hashtable to settings(and added 2 hashtables), but when I tried to use it, it thrown an exception(Object reference not set to an instance of an object.). Then I looked to app.config it looked like this:

<?xml version="1.0" encoding="utf-8" ?>
   <configuration>
     <configSections>
     </configSections>

   </configuration>

Then I added to app.config file two hashtables and now my config file looks like this:

<?xml version="1.0" encoding="utf-8" ?>

    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
        <section name="APPNAME.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
    </sectionGroup>
</configSections>

<userSettings>
    <APPNAME.Properties.Settings>
      <setting name="UserInfo" serializeAs="System.Collections.Hashtable">
        <value />
      </setting>
      <setting name="UserText" serializeAs="System.Collections.Hashtable">
        <value />
      </setting>
    </APPNAME.Properties.Settings>
</userSettings>

And when I tried to use the hashtables, it thrown the following exception: The value of the properties 'serializeAs' can not be parsed.

I've googled it but unsuccessful, I've searched on msdn also haven't found.

Micha
  • 5,117
  • 8
  • 34
  • 47
r.mirzojonov
  • 1,209
  • 10
  • 18

1 Answers1

1

The Hashtable does not support serialization to XML. And you have got only 2 options available in Settings.Settings. XML or string. Change your serialization option to

serializeAs="Binary"

Similarly in your Settings class you will have to specify the serialization option attribute as

[SettingsSerializeAs(SettingsSerializeAs.Binary)]
Ehsan
  • 31,833
  • 6
  • 56
  • 65