tags:

views:

168

answers:

3

We are having application which load our custom DLLs (these DLLs are implementing some interface) on runtime from the root of the application and execute a method through reflection.

If custom DLL have to read some value from config files then we have to copy these config settings into app.config file of the main application.

Is there any way where each custom DLL will have own configuring file named .config and read its configuration settings from this files itself.

+1  A: 

Load your DLL into a new AppDomain and set the AppDomainSetup.ConfigurationFile. This will let you create a separate config file for each custom DLL.

Mo Flanagan
A: 

I was certain there is a way to do this in the framework, just can't remember off the top of my head. What you're looking for is Per-Assembly configuration files, I remember reading an article about this Per Assembly Configuration Files

Student for Life
+1  A: 

If you're on .NET 2.0 or higher, you can manually tell the Configuration system to load the settings from any config file you want.

ExeConfigurationFileMap exeMap = new ExeConfigurationFileMap();
exeMap.ExeConfigFilename = "C:\Application\Default.config";

Configuration exeConfig = ConfigurationManager.OpenMappedExeConfiguration(exeMap, ConfigurationUserLevel.None);

Now you have your custom "Config" object and you can party on it! :-) Load a whole section by calling exeConfig.GetSection() or whatever you like.

Also check out this excellent three-part series on .NET 2.0 configuration system on CodeProject - highly recommended!

Marc

marc_s

related questions