Dabblernl
Dabblernl

Reputation: 16121

Where am I going wrong with the persistence of User scoped Settings?

I have a Boolean, user scoped setting. I access it through a referenced class library, called Settings. This class library has a Module with properties:

Module AppSettings
 Public Property MyBooleanSetting() As Boolean
    Get
        Return My.Settings.MyBooleanSetting
    End Get
    Set(ByVal value As Boolean)
        My.Settings.MyBooleanSetting = value
        My.Settings.Save()
    End Set
 End Property
End Module

I defined the setting in the Property pages of the Settings class library.

When other code manipulates the setting it will use code like:

Settings.MyBooleanSetting=True

While the code is running this works. But after a restart of the application the new value is not persisted. Where am I going wrong?

Upvotes: 0

Views: 427

Answers (2)

Dabblernl
Dabblernl

Reputation: 16121

Save your breath guys. The code did work after all. I used an other Property in the Viewmodel of my application that cached the Setting.MyBooleanSetting, but I forgot to read it in at application startup...

Upvotes: 2

Mark Hall
Mark Hall

Reputation: 54532

After looking at the Using My.Settings in Visual Basic 2005 MSDN article and these MSDN Forum Threads , I would say you need to verify which path is being used.

User-scope settings are specific for each user. They can be read and set safely by the application code at run time. These settings are stored in a user.config file. To be technically accurate, there are two user.configs per user per application—one for non-roaming and one for roaming. Although the Visual Basic 2005 documentation states that the user.config file will be named according to the user's name (joe.config), this is not the case. The user.config file is created in the \[Local Settings]Application Data\\\. Where:
• is the user data directory, either non-roaming (Local Settings above) or roaming.
• is the user name.
• is the CompanyNameAttribute value, if available. Otherwise, ignore this element.
• is the AppDomain.CurrentDomain.FriendlyName. This usually defaults to the .exe name.
• is the URL, StrongName, or Path, based on the evidence available to hash.
• is a SHA1 hash of evidence gathered from the CurrentDomain, in the following order of preference:
a.StrongName
b.URL

If neither of these is available, use the .exe path.

• is the AssemblyInfo's AssemblyVersionAttribute setting.

Upvotes: 2

Related Questions