Changing the name of a .NET application configuration file.

I have a VB6 application that calls a .NET assembly that references settings from the app.config file. By default, .NET searches for a configuration file named after a VB6 application. How can I redirect it to use a different configuration file name? This should become the default configuration file so that, for example, WCF parameters are read from it.

+7
app-config
source share
4 answers

You cannot change it. Each instance of AppDomain has a fixed app.config, which is installed using an instance of AppDomainSetup when creating a new application domain. Although you can get configuration information through AppDomain.SetupInformation , it has actually become read-only at the moment.

Given this, one option would be to create a new application domain from your Home function and configure the domain to use the required app.config.

+7
source share

AppDomain.CurrentDomain.SetData ("APP_CONFIG_FILE", @configFile);

+9
source share

You can force the application to read a specific configuration file using

System.Configuration.ConfigurationManager.OpenExeConfiguration(PATH_TO_CONFIG); 
+7
source share

Consider placing your configuration in an XML serialized object.

0
source share

All Articles