CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2011

    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:

    <add key = "someStringVar" value = "MYNAME" />

    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

  2. #2
    Join Date
    Jul 2011

    Re: using app.config..

    After you deploy your program, then change the deploy app.config file.
    You will see the change

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004

    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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.