An object-oriented programming language developed by Microsoft that can be used in .NET.
My.Settings.Save() persists only user‑scoped settings to the per‑user user.config file at run time. The design‑time files (Settings.settings, Settings.Designer.vb, *.vbproj.user, app.config) are not updated by My.Settings.Save and will always show the original design‑time values.
Key points:
-
Settings.settings,Settings.Designer.vb,*.vbproj.user, andapp.configare design‑time artifacts- These files are edited in Visual Studio (Project → Properties → Settings) and compiled into the application.
- They are not the files that
My.Settings.Save()writes to at run time. - After the app runs and saves settings, the updated values are stored in a
user.configfile under the user profile, not back intoSettings.settingsorapp.config.
- Only user‑scope settings are writable at run time
- Application‑scope settings are read‑only in code.
- User‑scope settings are read/write and can be changed and persisted with
My.Settings.Save(). - If
PropNamerefers to an application‑scope setting, the value will not be persisted as a user change.
-
SaveMySettingsOnExitis only about automatic saving on shutdown-
My.Application.SaveMySettingsOnExit = Falsejust disables the automatic save when the app exits. - Explicit calls to
My.Settings.Save()still persist user‑scope settings regardless ofSaveMySettingsOnExit.
-
- How to correctly persist and verify changes
- Ensure the setting’s Scope is
Userin the Project Designer (Settings tab). - Change the value in code:
My.Settings(PropName) = ConvertedValue My.Settings.Save() - Do not expect
Settings.settingsorapp.configto change; instead, read the value back viaMy.Settingsin a new run of the application:Dim currentValue = My.Settings(PropName) - If needed, locate and inspect the generated
user.configfile (this is where the runtime changes are stored).
- Ensure the setting’s Scope is
- If values appear to “revert”
- The apparent revert is usually because the design‑time files are being inspected instead of the runtime
user.config. - As long as the setting is user‑scoped and
My.Settings.Save()is called, the user’s changes are preserved between runs, independent of the design‑time defaults.
- The apparent revert is usually because the design‑time files are being inspected instead of the runtime
References:
- How to: Change User Settings in Visual Basic
- How to: Persist User Settings in Visual Basic
- WindowsFormsApplicationBase.SaveMySettingsOnExit Property
- Manage application settings (.NET)
- Accessing application settings (Visual Basic)
- Using Application Settings and User Settings
- Application Settings Overview