I am looking for a way to store a key-value pair in the application settings. From what I have found, key-value pair dictionaries are not serializable, and therefore cannot be stored in the application settings.
Currently I have tried all sorts of dictionaries and collections and all of them work, until I restart the application, then all the settings are gone.
Somewhere I read that a ListDictionary is serializable, but I still have not been able to get that to work. If someone could give me some VB.net examples of how to get this to work using the Application Settings, that would be great!
Thanks!
The Dictionary(Of TKey,TValue) class is actually serializable but in the binary sense. The XmlSerialization engine unfortunately cannot process anything that implements IDictionary and that’s what prevents it from working in application settings.
What I usually do to work around this is to create a small class that is XmlSerializable and represents a Key/Value pair. I think serialize a collection of those Key / Value pairs. It’s easily convertible back to a Dictionary(Of TKey,TValue) later.
For example, if the two items were Name and Student
Then I use the following to convert back and forth between an Array and a Dictionary