Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 137639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:08:17+00:00 2026-05-11T07:08:17+00:00

In my application, I need to change some value (Environment) in appSetting of app.config

  • 0

In my application, I need to change some value (‘Environment’) in appSetting of app.config at runtime.

I use AppSettingsReader

    private static AppSettingsReader _settingReader;      public static AppSettingsReader SettingReader     {         get          {             if (_settingReader == null)             {                 _settingReader = new AppSettingsReader();             }             return _settingReader;          }     } 

Then at some stage I do this

        config.AppSettings.Settings[AppSettingString.Environment.ToString()].Value = newEnvironment.ToString();         config.Save(ConfigurationSaveMode.Modified);         ConfigurationManager.RefreshSection('appSettings');   

However, next time I try to read ‘Environment’ like this

       string environment = (string)SettingReader.GetValue(AppSettingString.Environment.ToString(), typeof(System.String)); 

I end up with the old value of Environment.

I noticed that I can fix this by doing

_settingReader = new AppSettingsReader(); 

before I read ‘Environment’.

But I think creating a new instance is not the proper approach.

Maybe there is a way to let my SettingReader know, that the values have changed to use the same instance of it, but with refreshed values?

(Not a project-breaking question obviously, more of an educational one)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:08:17+00:00Added an answer on May 11, 2026 at 7:08 am

    AppSettingsReader doesn’t seem to have any method to reload from disk. It just derives from Object. Creating a new instance seems to be the only thing that would work… I may be wrong, but AppSettings are supposed to be read-only values for your app. More like configuration parameters for your application that can be tweaked before startup.

    For read-write application settings, I think the Settings mechanism with IDE support (System.Configuration.ApplicationSettingsBase) would be the preferred approach. This has Save and Reload methods. The designer-gen class makes the code far more readable too..
    Double click on the Properties Node under your Project in Solution Explorer. Find the Settings tab.

    Instead of

    sEnvironment = (string)SettingReader.GetValue(AppSettingString.Environment.ToString(), typeof(System.String)); 

    you could have typed properties like

    sEnvironment = Properties.Settings.Default.Environment; 

    The designer generated class exposes a synchronized singleton instance via the Default property.. which should mean you don’t need to reload.. you’d always get the latest value within the application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a console application which has its own App.config. I need to change
I need to distribute some sort of static configuration through my application. What is
I need to change database and settings when my customers load the application (xap)
In my Spring 3.1 application, I sometime need to change the default behavior of
I have some sliders in my application that allows the user to change ARGB
I'm writing an application and need some help with consistently storing and loading preferences
My question is related with the tests for some application in Symfony2. I use
I need some tangible guidance on implementing list of value objects in my distributed
I have an app that relies on some key value pairs where the value
During some debugging of our WebLogic application, I've noticed that the JSESSIONID doesn't change

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.