My.Settings problem

Grimface

Member
Joined
Sep 10, 2021
Messages
6
Programming Experience
10+
Hi,
I've added a checkbox to a form and created a variable within "Application Settings" to store its value so that its value is remembered when the application is shutdown. This works fine but I have a problem when I create a release version of the app and then create an installer for it.

When the app is initially installed, and then run, it creates a user.config file. This config file however does not reflect the contents of the values I entered in "Application Settings". If I set the boolean variable (associated to my checkbox) to True, in "Application Settings", the config file is set initially to False. I want to have an initial default value when the user first runs the app. How do I do this? Where am I going wrong?
 
Hi,

I've added a checkbox to a form and I want its value to be remembered when I close the app. To do this I created a variable within "Application Settings" which can be accessed using My.Settings.myVariableName (not the real variable name btw). Everything works fine but I have one problem that appears when a user first installs the application using its installer.

When the app is initially installed, and then run for the first time, the app creates a user.config file. This file contains all the variables that were created within the "Application Settings". The problem I have is that my new variable is in there but it doesn't have the initial value that I set up in "Application Settings". I want this to have an initial value of True but instead its always False (even though in "Application Settings" the value is defined as True). Is it possible to set the initial value in user.config? Where am I going wrong?
 
In "Application Settings" it's set to "User" scope not "Application" scope. If I'm looking at the correct App.config file its wrong in there too.

How do I fix this?
 
In "Application Settings" it's set to "User" scope not "Application" scope. If I'm looking at the correct App.config file its wrong in there too.

How do I fix this?
None of that answers my question.

With regards to the scope, it has to be User if you want the value to be read/write. Settings with Application scope are stored only in the main config file and are read-only through My.Settings. Settings with User scope have their default value stored in the main config file and their current value stored in the user config file for each Windows user who has run the app. When you run the app for the first time, the default value from the main config file is used. When you close the app, the current value is saved in the user config file and that is used on subsequent runs. If you ever delete the user config file, the default value will be used on the next run.

Now, please answer the question I actually asked. In the App.config file, what is the value for that setting? You need to open the config file from the Solution Explorer.
 
None of that answers my question.

With regards to the scope, it has to be User if you want the value to be read/write. Settings with Application scope are stored only in the main config file and are read-only through My.Settings. Settings with User scope have their default value stored in the main config file and their current value stored in the user config file for each Windows user who has run the app. When you run the app for the first time, the default value from the main config file is used. When you close the app, the current value is saved in the user config file and that is used on subsequent runs. If you ever delete the user config file, the default value will be used on the next run.

Now, please answer the question I actually asked. In the App.config file, what is the value for that setting? You need to open the config file from the Solution Explorer.
I've already answered your question. The value is incorrect there too. The value is False when it should be True. As I said before when the app is first run the user.config file is created with the wrong value. How do I fix this?
 
I'm currently running Visual Studio 2008. Does anyone know if this is a bug in that version? Or can anyone tell me what might be going wrong here and how to fix it? Thanks.
 
How exactly is this setting connected to the CheckBox? Have you bound it to the Checked or are you using code to copy the value back and forth? If you're doing the latter, you should do the former. You can do that via the (ApplicationSettings) node in the Properties window.

As for the value of the setting, if it is currently False, what happens if you set it to True on the Settings page of the project properties? Changes in the application should not affect that initial value that you set. Are you saying that, if you do that, it gets set back to False again at some point? Does it appear to be True when you public but is then False when you install?
 
I'm currently running Visual Studio 2008. Does anyone know if this is a bug in that version? Or can anyone tell me what might be going wrong here and how to fix it? Thanks.
Is there any particular reason that you're using such an old version? Unless you need it for compatibility, I suggest that you upgrade to VS 2019. The Community edition is free, unless you're in a team larger than five.

It's a long time since I used VS 2008 but I have no recollection of such an issue.
 
Sorry I thought I was clear in my initial question. The checkbox really isn't important but I copy the value to and forth (which works fine as it is at the moment). The problem is that I want the "Application Settings" value to have a default value of True. "what happens if you set it to True on the Settings page" - maybe I wasn't clear in my initial question but that's exactly what the problem is. It is set to True yet is False in the user.config. Why would that be? How do I fix it?

I'm using the older version as I work for a company and that's what was used to write the software in. That's the version that I have.
 
Can you determine whether the user config file is created at installation or after the first run? I would have thought the latter but I could be wrong. I can't see any valid reason that you would have the setting set to True in settings and True in the main config file and then, after publishing and installing, it's set to False in the main config file and the user config file. If that's what you're saying is happening then I can only conclude that something is broken in your VS installation.
 
I suggest that you create the simplest test project you can that demonstrates the issue, then provide us with a set of steps that we can follow to try to reproduce the issue.
 
Back
Top