views:

161

answers:

2

If I have a web application (with its own web.config) and a .dll it uses happens to have its own app.config which settings file wins when there is a conflict?

+2  A: 

No, you will not have any conflict because a .dll cannot have its own .config file.

Even if you put a .config file for your library in the same folder, the application is simply not going to pick up the values from it.

If you wish to use some of those values, you can merge them into your web.config.

Mark Seemann
The situation I'm looking at infront of me begs to differ...
Kirschstein
@Kirschtein: Which is?
Mark Seemann
There's an app.config file inside this library, with connection strings mentioned.
Kirschstein
@Kirschtein: They will not be picked up by the application by default. Is your scenario an add-in scenario. If so, the application may load the library into a separate AppDomain and point that AppDomain to the app.config in question, but otherwise those connection strings will not be loaded by the library unless they are specified in your web.config.
Mark Seemann
A: 

You can merge settings from another configuration file into your web.config file. This also allows you to override values aswell if they have the same key.

web.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings file="YourSettings.config">
    <add key="KeyToOverride" value="Original" />
    <add key="KeyToNotOverride" value="Standard" />
  </appSettings>
  ...

YourSettings.config

<appSettings>
  <add key="KeyToOverride" value="Overridden" />
  <add key="KeyToBeAdded" value="EntirelyNew" />
</appSettings>
James