0

I've added a StringDictionary to my project settings in VS2010. When I try to add members to it in my program, I get a NullReferenceException. When I try to initialize a value in its Value column in my project settings, it says my entry cannot be converted to StringDictionary. I'm sure it's looking for some XML code, but isn't there a better way to initialize the StringDictionary before compilation?

Additional info:

  1. Go to Menu -> Project -> [Project Name]> Properties... -> Settings

  2. Add a setting named mySetting of type System.Collections.Specialized.StringDictionary

  3. In your code add a line [ProjectName].Properties.Settings.Default.mySetting.Add("key","value");

  4. Run and get the exception.

user2320861
  • 1,391
  • 2
  • 11
  • 28
  • 1
    show your **code** please. – Selman Genç Mar 19 '14 at 15:09
  • Thanks! There's really not much code since it's all GUI in VS2010. I've added some steps on how to generate the error. – user2320861 Mar 19 '14 at 15:17
  • for value try `new System.Collections.Specialized.StringDictionary()` or something. This is just a guess though since I've not tried it myself but it looks like you need to initialize your dictionary and this seems like a not bad way of doing it. Or alternatively if that doesn't work try setting it via code in some kind of initialiser. – Chris Mar 19 '14 at 15:24
  • 1
    `StringDictionary` is basically only useful in C# 1.x. There's really no need t use it at all in later versions outside of possibly some legacy apps. Just use `Dictionary`. – Servy Mar 19 '14 at 15:26
  • Thanks. On Servy's suggestion I used a different class. `Dictionary` was not a type option that I could select so I'm now using a `Hashtable` instead. When I click on the `...` button in its `Value` column I'm not able to add anything to initialize it. – user2320861 Mar 19 '14 at 16:02

1 Answers1

0

I ended up just using two ArrayList settings in place of the one Hashtable setting.

user2320861
  • 1,391
  • 2
  • 11
  • 28