Hello.
I want to store my object in the application settings file.
My object class is NamedStringCollection (derived from StringCollection).
I saved it according MSDN (topic: ApplicationSettingsBase class overview).
But when I save my object (in the application settings file)
it looks like an object of a base class.
For ex:
There is a form with one button.
When I press the button the application saves my object.
private void button1_Click(object sender, EventArgs e)
{
ApplicationSettings Settings = new ApplicationSettings();
NamedStringCollection collection = new NamedStringCollection();
collection.CollectionName = "Collection1";
collection.Add("string1");
collection.Add("string2");
Settings.Collection = collection;
Settings.Save();
}
// this is the class I want to store
[Serializable]
public class NamedStringCollection : StringCollection
{
private string m_CollectionName = string.Empty;
public string CollectionName
{
get { return m_CollectionName; }
set { m_CollectionName = value; }
}
}
public class ApplicationSettings : ApplicationSettingsBase
{
[UserScopedSetting()]
[SettingsSerializeAs(SettingsSerializeAs.Xml)]
public NamedStringCollection Collection
{
get
{
return (NamedStringCollection)base["Collection"];
}
set
{
base["Collection"] = value;
}
}
BUT: when I open the application settings file I can see
...
<setting name="Collection" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>string1</string>
<string>string2</string>
</ArrayOfString>
</value>
</setting>
...
There is no information about "string CollectionName" from my class NamedStringCollection.
My object saved just like a base StringCollection class.
What I doing wrong Can you advise me what to read
Thank you.

ApplicationSettingsBase doesn't save custom class
Bernard_Lambert
I am working on the same problem. I have read the problem is your application does not have rights to the directory the file the application settings reside in. This is not the same as user settings which reside in a folder you have access to.
Here is one example of how to save your settings. Not sure if this is the right way yet.
http://www.developersdex.com/vb/message.asp p=1120&r=5066756
Muhammad.Umair
Change the serialization mechanism (I would suggest binary). XML Serialization of collection types only serialize elements in the collection. See:
http://msdn.microsoft.com/library/default.asp url=/library/en-us/dnexxml/html/xml01202003.asp
for more information.
Best regards,
Johan Stenberg