Question

I have integrated a dll with a service(exe). The dll has its own app.config file. But the code inside the dll for any Key/Value reference, it always refers to the exe's config file instead of the dll's config file. How the make the dll's config file as current to be used only when referred from inside the dll's code?

Was it helpful?

Solution

A DLL (or library file) cannot have its own config file. It will ALWAYS use the "hosting" applications configuration files.

The whole point of a DLL is that is can be used by many different applications and does not have configuration itself. Instead its "host" will contain the configuration information, so this is "by design".

OTHER TIPS

When your solution contains more than one project, you can add app.config in any of the project; but when you compile the code to generate final output, you get only one configuration file named <exeFileName>.exe.config . This is the only configuration file that will be read by the WinForms framework when the application is running.

If your DLLs (Assemblies in .NET) specify their own configuration file, those config files will not become a part of the final output (the respective assemblies).

To include the settings from the project specific config files, you will have to make those configuration entries (appSettings, connectionString, etc) into the main application's configuration file.

The DLLs can also read from the configuration file of the main application. Hence, when you make those entries in the <exeFileName>.exe.config file, all the DLLs, that are loaded can read values from the file.

Note: Take care of using unique names for the keys for each DLL as the configuration values are read using the keys.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top