0

I have a WCF service that calls into a DLL. The service has a web.config and the DLL has an app.config. I've written a custom app config section thanks to this question for the DLL. However, in the DLL when I make a call to ConfigurationManager.GetSection("...") it tries to read from the service's web.config.

How can I set it up so that the DLL reads from it's app.config while the service reads from it's web.config?

EDIT: It seems that when my I debug my service, my DLL gets copied to a strange temp folder (C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\f4d2cdd1\a59eb1c1\assembly\dl3\7c7f438f\b42518b4_f8f2cf01) but my DLL's config does not. If I copy the config there by hand, I can use OpenMappedExeConfiguration to read it. A regular call to ConfigurationManager continues to read the web.config even if the app.config is present.

I can't move the config settings from the app.config to the web.config because this DLL is shared between a WCF service and a REST service. I want them coming to a single DLL that offers core functionality for both. The DLL should read it's own config file and not either of the web.configs so that there's no chance of one service getting different values than the other.

Community
  • 1
  • 1
Corey Ogburn
  • 24,072
  • 31
  • 113
  • 188
  • 1
    Why don't you just add the custom section to the web service's web.config? app.config and web.config are essentially the same. It's all about context. When running in a web context (website, web app, web service, the settings are read from web.config). Class libraries, console apps (to name a few) use an app.config file. – HaukurHaf Oct 28 '14 at 21:08
  • The easy way would of course be to add the relevant information to the `web.config`. Is there a particular reason you cannot do that? (AFAIK, there is no easy way to do what you are asking, unless the dll is yours and you can customize the code) – flindeberg Oct 28 '14 at 21:08
  • The DLL and service are both mine. I can manipulate either one. And I would greatly like to avoid putting the config details in the service's config. – Corey Ogburn Oct 28 '14 at 21:10
  • possible duplicate of [How do I get the values from a ConfigSection defined as NameValueSectionHandler when using ConfigurationManager.OpenMappedExeConfiguration](http://stackoverflow.com/questions/13825323/how-do-i-get-the-values-from-a-configsection-defined-as-namevaluesectionhandler) – 500 - Internal Server Error Oct 28 '14 at 21:15

1 Answers1

0

If the call originates from web service, or anything that runs off web server such as IIS, then it will read only from web.config. If you are running console app or any app that does not run on web server then app.config will be used.

Filix Mogilevsky
  • 727
  • 8
  • 13