Mahesh
Mahesh

Reputation: 1784

configuring file for DLLs

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.

Upvotes: 4

Views: 842

Answers (3)

marc_s
marc_s

Reputation: 754200

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

Upvotes: 3

Student for Life
Student for Life

Reputation: 1033

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

Upvotes: 0

Maurice Flanagan
Maurice Flanagan

Reputation: 5289

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.

Upvotes: 1

Related Questions