14

I have a console application project and library project (dll) in one solution.

The library project has app.config file where I store some key value pair that I use in library. The console application references this dll.

I have another app.config file at console application where I have settings for console application.

When I run the program my library.dll always refers app.config from console application.

I want to separate the responsibility of each dll, so I want a dll to always refer to its own app.config file not that of the calling application.

In this case library.dll should use app.config of its own, not of the calling application.

how do I achieve this?

PramodChoudhari
  • 2,503
  • 12
  • 33
  • 46

1 Answers1

8

What you are asking has been asked many times again and again...

in fact you could instruct .NET to read configuration settings from another file, in your case will be something like library.dll.config, there are projects or classes to do this called something like assemblysettingsreader or similar.

My suggestion is anyway to do not do it. It sounds cool initially but think in this way, your library is not running alone, can be referenced by a console app, a web site or a wpf ui project, all these clients might need to customize the configuration and have different settings so it makes full sense to have the settings related to the calling application config files.

Davide Piras
  • 43,984
  • 10
  • 98
  • 147
  • 1
    +1 for suggesting to avoid config files for libraries. Better provide some kind of API in the library to pass configuration parameters from the client to to lib programmatically, and let the client store the parameters in his own config file. – Doc Brown Jun 17 '11 at 06:14
  • 7
    Davide, first paragraph of your answer is not helping at all, this question came as first result in my google search and I was expecting something good from a 5 vote answer. if you know many many solutions for it, you could specify one for people like me. your second paragraph is not true either. I have a login module that will always call an specific database regardless of what module is calling that dll so I need to configure it once, although I have multiple User interfaces. – AaA Apr 03 '12 at 03:51
  • 1
    It would be useful if you can provide a solution to the question. – Rejeev Divakaran Jun 28 '12 at 16:38