Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changes in App.config do not reflect after restarting the application

I am using an app.config file to store the dynamic parameters of my application. The problem is, when I change a value in app.config file, and start the application, it doesn't load the new value from config file. Seems like the values in app.config file are being read and embedded in exe file only at compile time!

This is how I read the config file:

public class Helper
{
    static Helper()
    {
        Foo = ConfigurationManager.AppSettings["Foo"];
    }
    public static string Foo { get; set; }
}

Am I missing something?

like image 292
B Faley Avatar asked Nov 29 '22 11:11

B Faley


1 Answers

Are you sure you are changing the correct file? You don't want to change the app.config file, but the <exename>.exe.config file, in the same directory as the .exe

The app.config file is what you edit in the ide, but when you compile your app this file is renamed to <exename>.exe.config and copied to the output directory when you compile. The .exe looks for a file with the same name as itself with the .config extension when looking for the default configuration.

like image 186
Sam Holder Avatar answered Dec 15 '22 02:12

Sam Holder