adicto_al_futbol
adicto_al_futbol

Reputation: 11

Program cannot find app.config

// Set LastRun to now
config.AppSettings.Settings["LastRun"].Value = DateTime.Now.ToString(); // Save all settings config.Save(ConfigurationSaveMode.Modified);

This code was working fine in my development server but not in my production server. It seems like my program is unable to communicate with my app.config file. I have checked all the "obvious" . . Any ideas ... ?

Upvotes: 0

Views: 3115

Answers (1)

dblood
dblood

Reputation: 1778

From your code example, I cannot tell how your config variable is initialized. But, from the comments, you have a web app. Unless you are attempting to load a specific app.config file, the web app will attempt to get AppSettings from web.config.

It's not a good idea to programatically change the values of web.config. Changing web.config will cause an application restart.

If you have a different app.config for storing this type of information, that would be better than trying to change web.config. But you'll have to specifically load the file, something like this:

Configuration config = WebConfigurationManager.OpenWebConfiguration("yourPath\app.config");

ConfigurationManager.OpenExeConfiguration() is intended for use within an executable application not a web app. Try using WebConfigurationManager as shown above.

You find some more information in this SO question/answers.

More information can be found in this SO question/answer.

Upvotes: 2

Related Questions