[2008] My.Settings not saving?!
Hey,
I have used My.Settings for quite some time now, in both VS2005 and now in 2008, but never noticed this behaviour yet... I must be forgetting something trivial?!
I create a StringCollection setting and manually enter some data (strings).
I write some code to handle this, and I get it to work.
Then, I manually add some new strings (and edit the older ones) in the Settings page, save the project, and run my code again.
For some reason, the last changes have not been saved... Whenever I look in the settings page, I see them there, but my code cannot recognize them...
// EDITED //
Am I forgetting something, or is there something wrong with VS?
EDIT
I did add "My.Settings.Reload()" at the start of the code that displays the value... Not sure if I need to do that, but it can't hurt, can it?
EDIT2
It only seems to do this with a StringCollection. If I try to manually change a normal String than it picks it up fine.\
I can reproduce this doing the following:
- Create new project.
- Add a StringCollection setting via the project's properties 'Settings' page, the StringCollection setting is called "Test" and it's value is one line with "line1" and a second line with "line2".
- Make my program display the lines in a Msgbox: "MessageBox.Show(My.Settings.Test(0) & " " & My.Settings.Test(1))"
- Output is "line1 line2"
- Manually change the settings lines to "line1 And some text" and "line2 And some text".
- Save project
- Run program again, output is still "line1 line2".
...
Re: [2008] My.Settings not saving?!
Hit the Syncronize button in the upper left of the Settings page, the .config file will be recreated and your new defaults will be set.
Re: [2008] My.Settings not saving?!
Never used that before... anyway, it says:
Code:
No user.config files were found in any of the following locations:
[blank lines]
I do see a 'app.config' file in the Solution explorer, which contains the right strings:
Code:
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>line1 And some text</string>
<string>line2 And some text</string>
</ArrayOfString>
Re: [2008] My.Settings not saving?!
look in the bin/debug & bin/release folders... delete any config files in there.
-tg
Re: [2008] My.Settings not saving?!
What do you have the Scope set for the string collection. With the scope set to User I can reproduce you issue, but it resolves itself when I hit syncronize or also My.Settings.Reset also will reload the defualt User settings you put in the settings desginer. With the Scope set to Application the settings are always in sync with the designer as far as I have seen.
Re: [2008] My.Settings not saving?!
Scope is set to user. If I set it to Application I can't edit the values, right? I need to be able to edit them so I need User.
I tried removing the config files from the debug (and release, which was empty) folder, which didn't help.
Then I deleted the 'app.config' file via the solution explorer, and this time it worked. The changes I made came through.
However, if I make some new changes now, the same problem arises again...
So basically, I have to delete the app.config file everytime I might make a change to the default settings...? Seems a bit weird to me...
Re: [2008] My.Settings not saving?!
click the app.config file in the solution explorer, and view its properties (right click -> properties) .... there's a property called build action.... or something like that, has to do with what to do with the file when doing a build, set it to copy if newer. I'm thinking that right now it's set to not copy....
-tg
Re: [2008] My.Settings not saving?!
techgnome has a point but he is overlooking the fact that the other settings are updating fine. I am unable to replicate this problem from my side.
Have you checked what happens when you edit the settings directly in the app.config file?
Re: [2008] My.Settings not saving?!
Ray - did you check the age of this post first? It's nearly a year old. And what "other settings"?
-tg
Re: [2008] My.Settings not saving?!
Quote:
Originally Posted by
techgnome
click the app.config file in the solution explorer, and view its properties (right click -> properties) .... there's a property called build action.... or something like that, has to do with what to do with the file when doing a build, set it to copy if newer. I'm thinking that right now it's set to not copy....
-tg
i'm having the same problem, i changed Copy To Output Directory to "copy if newer" but the problem persists. here is what i have:
Code:
Dim existinglist As New List(Of clsReader)
for each...
existinglist.add(...)
next
My.Settings.List = existinglist
My.Settings.Save()
My.Settings.Reload()
in Watch window I can see My.Setings.List go to 0 when I execute Reload()
edit
I checked other values, and they persist. For example, My.Settings.ReaderTimeout is an Integer. My.Settings.List is System.Object. could this be a problem?
edit2
is there a size limit? i just tried serializing to memory stream, still no go. im going to try string next
spying on the user.config file, there is no change to the <setting name="Readers" serializeAs="Xml">
I've gone as far as editing the Setting.Settings file and Settings.Designer to include
Code:
Public Property Readers() As List(Of clsReader)
Get
Return CType(Me("Readers"), List(Of clsReader))
End Get
Set(ByVal value As List(Of clsReader))
Me("Readers") = value
End Set
End Property
as per this this and this.
no dice.
Re: [2008] My.Settings not saving?!
to hell with it, i broke my project.
Code:
Dim xs As New XmlSerializer(existinglist.GetType)
Dim sr As New StringReader(My.Settings.Readers)
Dim sw As New StringWriter
xs.Serialize(sw, existinglist)
My.Settings.Readers = sw.ToString
Dim existingreaders As List(Of clsReader) = xs.Deserialize(sr)
Re: [2008] My.Settings not saving?!
unxzst, you should probably post in a new thread.
EDIT: Unless you're done, in which case ignore me :)
Re: [2008] My.Settings not saving?!
Code:
'VB2010
'My.Settings.newVers = True in Designer
'My.Settings.foo = StringCollection
If My.Settings.newVers Then
My.Settings.Upgrade()
My.Settings.newVers = False
End If
Debug.WriteLine(My.Settings.foo(0))
Debug.WriteLine(My.Settings.foo(1))
Debug.WriteLine(My.Settings.newVers)