I have a windows application that uses an assembly that stores some configuration settings in the default application settings.
The settings can be changed in run time and are persisted thus:
Properties.Settings.Default.SelectedCOMPort = options.SelectedCOMPort;
Properties.Settings.Default.Save();
The settings are saved correctly and I confirm this by looking at the user.config file saved in the users application directory E.g.
C:\Documents and Settings\e399536\Local Settings\Application Data\MyCompany\MyTool
However when the tool is closed and then started again all the settings are loaded with their default values.
Checking the user.config file once the application is running confirms that the settings are still as saved.
The settings are loaded thus:
options.SelectedCOMPort = Properties.Settings.Default.SelectedCOMPort;
Why are the default settings being used and not the saved ones?
Have I missed something??
@ Tenaciouslmpy The settings are loaded during the constructor of the assembly, which itself is loaded in the form load event of the main assembly.
@ Austin This is a standalone app that I am debugging in Visual Studio.
You can use the My.Settings.Save method to persist changes to the user settings. Typically, applications are designed to persist the changes to the user settings when the application shuts down. This is because saving the settings can take, depending on several factors, several seconds.
Logging in to a computer is as easy as typing a password (if any) and tapping the sign-in button. If your PC refuses to load your profile and there's a blue screen with a 'User profile cannot be loaded' error message on it, then there's a problem with some files or services that powers your PC's user profile.
How to: Persist User Settings in Visual Basic. You can use the My.Settings.Save method to persist changes to the user settings. Typically, applications are designed to persist the changes to the user settings when the application shuts down. This is because saving the settings can take, depending on several factors, several seconds.
Nine Options for Managing Persistent User State in Your ASP.NET Application ASP.NET provides many different ways to persist data between user requests. You can use the Application object, cookies, hidden fields, the Session or Cache objects, and lots of other methods. Deciding when to use each of these can sometimes be difficult.
If you are recompiling the application between runs, note that it will consider that a new version of the app and will not automatically load per-user settings. You need to call Settings.Default.Upgrade in this situation.
One way to do this only when needed is to add a NeedsUpgrade setting (value True) to the application's default per-user settings. On app startup, check if NeedsUpgrade is true. If so, call Upgrade, set NeedsUpgrade to False, and save the settings. The next time the app version changes, NeedsUpgrade will reset to True and you'll auto-call Upgrade to bring in any existing user settings again.
Make sure you're setting NeedsUpgrade after calling Upgrade, or it will get wiped out when the settings are upgraded.
if (Settings.Default.NeedsUpgrade)
{
Settings.Default.Upgrade();
Settings.Default.NeedsUpgrade = false;
Settings.Default.Save();
}
This sounds like you're debugging the application from Visual Studio when every time you start a new session you start with the default data.
If you're seeing this with an installed release, then I would guess you're not actually using the string values when you think you are.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With