Question

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?

Was it helpful?

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.

OTHER TIPS

The answer to your question is YES

And another point to note here is that the app.config file of your main project is always deployed (not the referenced project) unless you explicitly copy the app.config of referenced project. Therefore it is always better to do all your work on app.config of your main project which in your case is A

If i understand correctly you have two projects in ur solution

  1. Project A (WebService)
  2. Project B (Class library)

if that's the case - Yes. ConfigurationManager.AppSettings will read from the config file of the startup project i.e Project A in ur case.

However if you have different project which run independently for e.g. two different service projects Service1 and Service2 both will refer to their respective app.config/web.config files.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top