Hi Everyone,
I am changing values in app.config file they are changing in runtime but they are not reflecting on xml app.config file.can anyone tell the reason? please find below for more detailed information.
Thanks in adavance.
Hi Everyone,
I am changing values in app.config file they are changing in runtime but they are not reflecting on xml app.config file.can anyone tell the reason? please find below for more detailed information.
Thanks in adavance.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jayraj ChhayaPosted Jan 9, 2024, 6:17 AM
When working with the app.config file in a .NET application, it's important to understand how the configuration system works. The app.config file is used as a template to generate an XML configuration file during the build process. This XML file is then used at runtime to provide configuration settings to the application.
The reason why changes made to the app.config file at runtime are not reflected in the XML app.config file is because the XML file is only read once, during the application startup. Any modifications made to the app.config file during runtime will not be automatically written back to the XML file.
To ensure that changes made to the app.config file are reflected in the XML app.config file, you can use the ConfigurationManager class provided by the .NET framework. This class provides methods to read and write configuration settings at runtime.
Here's an example of how you can update a configuration setting and save it back to the XML app.config file:
By using the ConfigurationManager class and saving the changes back to the XML app.config file, you can ensure that modifications made at runtime are persisted and reflected in the XML file.
Tuhin PaulPosted Jan 9, 2024, 5:29 AM
The behavior you’re observing is expected. When you change values in the app.config file at runtime, they are not reflected in the YourApplicationName.exe.config file. This is because the app.config file is designed to store configuration values that are not supposed to change during runtime .
When you compile your application, the app.config file is copied and renamed to YourApplicationName.exe.config in the output directory . Therefore, if you want your changes to be taken into account, you should modify the YourApplicationName.exe.config file, not the app.config file .
If you need to change configuration values dynamically, you might want to use a different storage mechanism like a file or a database . If you still want to use the app.config file, you can use the ConfigurationManager.RefreshSection("appSettings") method after modifying the YourApplicationName.exe.config file. Then, refetch the value you need using ConfigurationManager.AppSettings["someKey"], which should return the new value.
Any changes made to the app.config file at runtime will not persist after the application is closed . If you need to save these changes permanently, consider writing them to a separate user-specific configuration file or another form of persistent storage.
Anandu G NathPosted Jan 9, 2024, 4:40 AM
Make Copy always true in the property of config file
Naimish MakwanaPosted Jan 9, 2024, 4:10 AM
The behavior you’re observing is expected. When you change values in the
app.configfile at runtime, they are not reflected in theYourApplicationName.exe.configfile. This is because theapp.configfile is designed to store configuration values that are not supposed to change during runtime123.When you compile your application, the
app.configfile is copied and renamed toYourApplicationName.exe.configin the output directory12. Therefore, if you want your changes to be taken into account, you should modify theYourApplicationName.exe.configfile, not theapp.configfile12.If you need to change configuration values dynamically, you might want to use a different storage mechanism like a file or a database2. However, if you still want to use the
app.configfile, you can use theConfigurationManager.RefreshSection("appSettings")method after modifying theYourApplicationName.exe.configfile. Then, refetch the value you need usingConfigurationManager.AppSettings["someKey"], which should return the new value24.Here’s an example of how you can do this:
Remember, any changes made to the
app.configfile at runtime will not persist after the application is closed3. If you need to save these changes permanently, consider writing them to a separate user-specific configuration file or another form of persistent storage.Thanks
Ali BenchaabanPosted Jan 8, 2024, 6:20 PM
We can't see the code mate
NaveenPosted Jan 8, 2024, 4:49 PM
i already did that but still not working .please look at whole code.
Sachin SinghPosted Jan 8, 2024, 3:47 PM
Try this
Ali BenchaabanPosted Jan 8, 2024, 3:39 PM
Hello,
The reason behind why the app.config file is not getting reflected during update in Run time is as follows:
So every time you need to re-build to your app to reflect the changes.
Regards,
BENCHAABAN Ali