Search code examples
c#visual-studio-2010projects-and-solutionsprojects

Referenced Projects and Config Files


I am a bit confused on this subject.

The situation I have is I have two separate projects in C#:

  1. are service (A)
  2. a helper project (B)

Both are in seperate solution files. (A) has reference (B) What i am confused about is that e.g. I have app.config file in (A), so when I refer to:

ConfigurationManager.AppSettings["XYZ"]

in project (B). does that mean I am using project (A)'s app.config file?


Solution

  • Yes, the ConfigurationManager class and the underlying configuration file is available to the whole AppDomain instance. Since your library will be getting used by the service, it becomes part of the service's AppDomain and inherits access to that configuration file.

    If you want the other binary (project B) to have it's own, then you need to create an instance of it in it's own AppDomain. It's more trouble than it's worth, so I wouldn't try to look into doing this.

    Any AppDomain that will use this library will be providing it's config settings. This means that if the library has it's own settings the service itself does not use, then you need to ensure any executable that uses the library has the settings present.

    So if you have a solution that has ProjA (Console app), ProjB (WinForms app), and they both use ProjC (shared library), make sure the settings ProjC is looking for are in both ProjA and ProjB's config files since ProjA and ProjB are their own AppDomain instances when run.