My.Settings strange problem
I have been trying to figure out why one of my settings will not properly save. Here is what the user.config file looks like:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<userSettings>
<Project_Tracker.My.MySettings>
<setting name="MainLocation" serializeAs="String">
<value>86, 112</value>
</setting>
<setting name="Engineer" serializeAs="String">
<value />
</setting>
</Project_Tracker.My.MySettings>
</userSettings>
</configuration>
Notice that the setting for "Engineer" is not propery formatted. If I manually change the file, it works fine until the next time it is saved. Then it looks like above, again.
The "MainLocation" always works properly.
Can anyone tell me how to solve this problem?
Thanks.
FloridaJohn wrote: |
| I have been trying to figure out why one of my settings will not properly save. Here is what the user.config file looks like: <?xml version="1.0" encoding="utf-8"?> <configuration> <userSettings> <Project_Tracker.My.MySettings> <setting name="MainLocation" serializeAs="String"> <value>86, 112</value> </setting> <setting name="Engineer" serializeAs="String"> <value /> </setting> </Project_Tracker.My.MySettings> </userSettings> </configuration> Notice that the setting for "Engineer" is not propery formatted. If I manually change the file, it works fine until the next time it is saved. Then it looks like above, again. The "MainLocation" always works properly. Can anyone tell me how to solve this problem? Thanks. |
|
Are you saving it something like? >>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<userSettings>
<Project_Tracker.My.MySettings>
<setting name="MainLocation" serializeAs="String">
<value>86, 112</value>
</setting>
<setting name="Engineer" serializeAs="String">
<value>77, 88</value>
</setting>
</Project_Tracker.My.MySettings>
</userSettings>
</configuration>
Regards,
S_DS
Actually, what I am trying to save should look something like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<userSettings>
<Project_Tracker.My.MySettings>
<setting name="MainLocation" serializeAs="String">
<value>86, 112</value>
</setting>
<setting name="Engineer" serializeAs="String">
<value>jrl<value />
</setting>
</Project_Tracker.My.MySettings>
</userSettings>
</configuration>
I am using My.Settings.Save() to generate the above file. According to the documentation, it should all happen automatically. It does for "MainLocation", but writes incorrect syntax for "Engineer".
Thanks for your help!
I noticed an error in what I just posted. I am trying to get the file to look like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<userSettings>
<Project_Tracker.My.MySettings>
<setting name="MainLocation" serializeAs="String">
<value>86, 112</value>
</setting>
<setting name="Engineer" serializeAs="String">
<value>jrl</value>
</setting>
</Project_Tracker.My.MySettings>
</userSettings>
Hmmm... could you try overriding the save method in your settings class (click on view code and add a save method) and check if the string is set to an empty string?
Remember to call the base class:
Public Overrides Sub Save()
System.Diagnostics.Debug.Assert(My.Settings.Engineer <> "", "Huh, we are trying to save an empty string...")
MyBase.Save()
End Sub
Best regards,
Johan Stenberg
Yep, that helped a lot!
I had an event in one of my controls that was raised as I was closing my form. It just so happened that event changed the value of the setting to nothing (incorrectly), right before it was saved.
Thanks for your help Johan!