D
Danny
Hello,
I was wondering if anyone knew if it was possible to make changes to
an application's App.config file at runtime and then be able to access
those changes immediately.
The following is an example of what I'm trying to achieve:
I tried a test by creating a simple app Test.exe that has some basic
settings made available to it in the runtime file Test.exe.config.
E.g.
<appSettings>
<add key="setting" value="123" />
</appSettings>
I then started the app, and printed out the setting through a call to
ConfigurationSettings.AppSettings["setting"] with result:
setting = 123
Then, while the app was still running, I changed the value of the
setting as such, and saved the file Test.exe.config:
<appSettings>
<add key="setting" value="abc" />
</appSettings>
Again I printed the out the setting through the call to
ConfigurationSettings.AppSettings["setting"] but there was no change,
the output was still
setting = 123
whereas I would expect it to be
setting = abc
It seems that the contents of the App.config file are loaded into some
cache upon startup, and any physical changes to the file itself go
unnoticed until the application is instantiated again.
Is this the case? If so, any ideas on how to go about achieving what I
am trying to do. I figure the only option would be to create a custom
configuration class that reads from some custom config file when
requested.
Hope to hear from someone,
Danny
I was wondering if anyone knew if it was possible to make changes to
an application's App.config file at runtime and then be able to access
those changes immediately.
The following is an example of what I'm trying to achieve:
I tried a test by creating a simple app Test.exe that has some basic
settings made available to it in the runtime file Test.exe.config.
E.g.
<appSettings>
<add key="setting" value="123" />
</appSettings>
I then started the app, and printed out the setting through a call to
ConfigurationSettings.AppSettings["setting"] with result:
setting = 123
Then, while the app was still running, I changed the value of the
setting as such, and saved the file Test.exe.config:
<appSettings>
<add key="setting" value="abc" />
</appSettings>
Again I printed the out the setting through the call to
ConfigurationSettings.AppSettings["setting"] but there was no change,
the output was still
setting = 123
whereas I would expect it to be
setting = abc
It seems that the contents of the App.config file are loaded into some
cache upon startup, and any physical changes to the file itself go
unnoticed until the application is instantiated again.
Is this the case? If so, any ideas on how to go about achieving what I
am trying to do. I figure the only option would be to create a custom
configuration class that reads from some custom config file when
requested.
Hope to hear from someone,
Danny