File setup for DLL

We have an application that loads our custom DLLs (these DLLs implement some interface) at runtime from the root of the application and execute the method by reflection.

If the user DLL needs to read some value from the configuration files, we must copy these configuration parameters to the app.config file of the main application.

Is there a way in which each custom DLL will have its own configuration file named .config and read its configuration settings from these files.

+4
source share
3 answers

If you are using .NET 2.0 or later, you can manually tell the configuration system to load the settings from any configuration file that you want.

ExeConfigurationFileMap exeMap = new ExeConfigurationFileMap(); exeMap.ExeConfigFilename = "C:\Application\Default.config"; Configuration exeConfig = ConfigurationManager.OpenMappedExeConfiguration(exeMap, ConfigurationUserLevel.None); 

Now you have your own custom "Config" object and you can participate in it! :-) Download the entire section by calling exeConfig.GetSection () or whatever.

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

Mark

+3
source

Download your DLL to the new AppDomain and set AppDomainSetup.ConfigurationFile. This will allow you to create a separate configuration file for each user DLL.

+1
source

I was sure that there was a way to do this within the framework, I just can’t remember from my head. What you are looking for is configuration files for each assembly, I remember reading an article about it in the assembly configuration files

0
source

All Articles