|
-
July 13th, 2011, 12:51 AM
#1
using app.config..
hi all,
i was using app.config for variables that i use in the code where i can have users to change some values without compiling the code
for example, in app.config i have:
<appSettings>
<add key = "someStringVar" value = "MYNAME" />
</appSettings>
in the main code (program.cs)
string myVar;
myVar = ConfigurationSettings.AppSettings["someStringVar"];
supposedly myVar = MYNAME.. when I compile the code with this value it reads this as MYNAME.
now, i open this file in the /Debug directory (this is where the compiled file .exe is saved together with the other files) = Program1.vshost.exe.config
when I change the value to "ME", saves the file and run the .exe, it still gives me the first value of "MYNAME" instead of the new value "ME".
I placed Console.WriteLine to show/display the value of myVar and it always displays "MYNAME" as it's value.
Why is it that it don't change to the new value?
thanks in advance
-
July 13th, 2011, 05:02 AM
#2
Re: using app.config..
After you deploy your program, then change the deploy app.config file.
You will see the change
-
July 13th, 2011, 05:57 PM
#3
Re: using app.config..
The reason it doesn't change is because the app config files get autogenerated when you compile your app.
When you run your program under the ide, the *.vshost.config file is used. When you run your program outside the ide, the <programname>.exe.config file is used.
Both of these config files are regenerated from the App.Config file when you compile your app.
So if you debug your app (which generates new *.config files), change a setting in the vshost.config file and then debug your app again, the change will be overwritten.
If you need a change to persist, make a change to the program.exe.config file and run the app outside the ide.
...or make a change to the App.Config file.
Lastly, you should be using the ConfigurationManager class instead of ConfigurationSettings class as the latter has be deprecated.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|