Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

web.config overrides app.config...why?

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 Answers

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)

like image 196
Damien_The_Unbeliever Avatar answered Dec 06 '25 07:12

Damien_The_Unbeliever