I have a VB6 app which calls a .NET assembly, which references settings from the app.config file. By default, .NET looks for a config file named after the VB6 app. How can I redirect it to use a different config file name? This needs to become the default config file so that e.g. WCF settings are read from it.
+3
A:
You can force the application to read a particular config file using
System.Configuration.ConfigurationManager.OpenExeConfiguration(PATH_TO_CONFIG);
Igor Zelaya
2009-01-13 16:03:10
Thanks. I need this to become the "default" app.config file so that e.g. WCF settings are read from it. I'll update the question to be more specific.
Ian Horwill
2009-01-13 16:22:38
+4
A:
You can't change it. Each AppDomain instance has a fixed app.config that is set via an AppDomainSetup instance when a new app domain is created. Although you can get the setup information via AppDomain.SetupInformation it has effectively become readonly at this point.
Given this, one option may be to create a new app domain from within your Main function and configure the domain to use the app.config you require.
Sean
2009-05-20 11:59:07
Thanks, that's what I did in the end. The main (.NET) app sets APPDOMAIN_MANAGER_TYPE and APPDOMAIN_MANAGER_ASM environment variables to cause a custom AppDomainManager to be used, which overrides InitializeNewDomain to set the AppDomainSetup.ConfigurationFile property to point to the shared .exe.config file. Easy when you know how!
Ian Horwill
2009-06-12 09:33:50