Web.config overrides app.config…why?

Up vote 0 down vote favorite share g+ share fb share tw.

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? .net configuration web-config app-config configuration-files link|improve this question edited Jun 3 '10 at 9:59Damien_The_Unbeliever33.9k1338 asked Jun 3 '10 at 9:50CodeWorks2,1911531 93% accept rate.

You seem to be determined to have some of your configuration somewhere other than the web. Config file, when this isn't the norm. If you could add to your question why you want/need this configuration to be stored elsewhere, maybe some other answers could be added to help you.

– Damien_The_Unbeliever Jun 3 '10 at 10:44 I didn't realise that the web. Config was global for the entire application. I thought it was accessible only in that DLL, therefore I wanted to store all the connection strings and custom settings in a middle layer which can be called from other DLLs.

– CodeWorks Jun 3 '10 at 10:49.

App. Config for DLLs will never be used. App.

Config for EXEs is renamed to .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).

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? – CodeWorks Jun 3 '10 at 10:03 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.

– CodeWorks Jun 3 '10 at 10:21 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 Jun 3 '10 at 10:25 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)... – CodeWorks Jun 3 '10 at 10:28.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions