Do you have to restart a windows service if you change the app.config?

Do you have to restart a windows service if you change the app.config?


Solution 1:

Yes, you do:

.Net framework will read the app.config once, and never touch the app.config again. That is why you have to restart the application to pick up the change.

Why does not .Net framework detect that app.config has changed, and refresh all the config data?

The reason is simple, this is not possible in general.

Let’s use Raymond’s “imagine this could be done” logic here...

Solution 2:

I've used this before. Essentially this reloads the specified section before retrieving the value. Quite possibly less efficient than a config file watcher that refreshes on demand, but certainly effective used carefully.

  ConfigurationManager.RefreshSection("appSettings")
  sValue = ConfigurationManager.AppSettings(name)

Solution 3:

No, you don't have to. But if you want for changes in app.config to take effect, you might need to restart it. Or you might want to implement a custom configuration file watcher mechanism which would alter services' settings on the fly.