How can I force the reload of a .config file

  • Thread starter Thread starter Jean-Francois Hamelin
  • Start date Start date
J

Jean-Francois Hamelin

Hi,

I want to use the System.Configuration.ConfigurationSetting.AppSettings
member function to retrieve settings from the my .config file. I have an
option form that change the some values and save them in the .config file
via a XML DOM document.

When I read back values from
System.Configuration.ConfigurationSetting.AppSettings member function it is
the original one, is there a way to force reading back the .config file ?

Thanks
JF
 
Hello,

Thanks for your post. As I understand, the problem you are facing is that
you cannot get updated from application configuration file. Please correct
me if there is any misunderstanding. I now share the following information
with you:

The AppSettingsReader class reads the application settings when the default
AppDomain is loaded, and then those settings are cached for the lifetime of
the AppDomain. Based on my experience, there are two methods to work around
this problem:

Method 1
========
Whenever you want to force reading back the .config file, you can create a
second AppDomain with the appropriate .config file and read the information
from the new AppDomain:

AppDomainSetup.ConfigurationFile Property
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemappdomainsetupclassconfigurationfiletopic.asp

Method 2
========
I recommend that you can also create a custom Application Configuration
class which loads the configuration dynamically. You might consider also
using Mike Woodring's nice little extension class:

Arbitrary Configuration File Parser
http://www.develop.com/technology/resourcedetail.aspx?id=a69c6aa4-728c-4edb-
b221-d52ecc9b3c53

In addition, I believe the following MSDN article is helpful:

Persisting Application Settings in the .NET Framework
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/ht
ml/persistappsettnet.asp

Please feel free to let me know if you have any problems or concerns.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top