Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the .NET application configuration file name

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.

like image 875
Ian Horwill Avatar asked Jan 13 '09 16:01

Ian Horwill


People also ask

Which file is the place where we can change the configuration of the app?

The machine configuration file, Machine. config, contains settings that apply to an entire computer. This file is located in the %runtime install path%\Config directory.

Where are .NET application settings stored?

It is in a folder with your application's name in Application Data folder in User's home folder (C:\documents and settings\user on xp and c:\users\user on Windows Vista).


2 Answers

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.

like image 101
Sean Avatar answered Oct 28 '22 07:10

Sean


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

like image 21
Sony Avatar answered Oct 28 '22 08:10

Sony