views:

130

answers:

1

Hi,

I have two DLLs: one with a web.config, another one with app.config

I moved the connection strings from web.config to app.config so that it can be used by other DLLs.

Now, when I call ConfigurationManager.GetSection("SomeSection") , the application looks for a web.config, when it should be looking for the app.config. It doesn't make sense why it does it because web.config is in a separate DLL.

Can anybody explain this please?

+1  A: 

app.config for DLLs will never be used.

app.config for EXEs is renamed to <Application>.exe.config, and used by the EXE

web.config is used by websites/applications.

Essentially, if Visual Studio helpfully adds an app.config file to a DLL project for you, all it's giving you is something to copy and paste into the appropriate final config file - either the app.config of the EXE, or the web.config of the web site/application.

@vikps comment: Ignoring, for a second, the issues of website subdirectories and configSource, you can not have more than one configuration file involved in the configuration of an application. And neither subdirectories or configSource will help you, in this instance.

With configSource, the application can specify that an entire configuration section should be read from an alternative configuration file. But you can only do this if the entire configuration section exists in this other file (you cannot, for instance, have a connectionStrings section in the web.config, and also load some more connection strings from another source)

Damien_The_Unbeliever
Thanks for the reply. I need a configuration file for the class library. It will store connection strings and other settings. How do I create an exe of the config file?
vikp
Can you please confirm that it's not possible to have 1 config file in each DLL? I have over 5 DLLs and I was hoping I could have a configuration file for each of those DLLs. Can I use a confiSource which points to a different DLL? Otherwise all the config files must reside in the startup project? Which is a web project in my instance.
vikp
All of the configuration that those DLLs are going to read will have to be in the web.config - you'll have to merge all of this configuration information together yourself. Like I said, configSource was unlikely to solve your problem, because it's basically a way of saying "read *all* of the connection strings from this one, other, file".
Damien_The_Unbeliever
Do I have any alternatives? Web config is a must for a web project, therefore it can't be moved anywhere, so the only thing I can do is break it down into few files. I could have custom configuration files within my DLLs (probably in XML)...
vikp