0

I have a solution with 2 projects; lets call them project A (base project) and project B (used for some testing of the methods in project A) In project A, I use App.config to store some configuration options like a connectionstring and appsettings.

When I set project B as startup project and I run a method from A, the program looks for the configuration in app.config of B (instead of A), where these configoptions do not exist. This results in a "System.NullReferenceException".

(When I set A as my startupproject, and I access the method from within A, it works fine) How can I solve this? I want my project A to always use its own app.config file.

Wim Rijken
  • 33
  • 5
  • App.config is always picked up from the startup application. There is very less you can do here. You can write a post build event for Project A to copy app.config to Project B. – Chetan Jul 10 '18 at 10:02

2 Answers2

0

As stated before the application loaded determines which app.config is loaded. If it is possible try to extract the method you like to test in project library C.

Another solution is loading in config setting in a eternal config file. Which is explained here Write appSettings in external file

Both A and B needs some editing in their own app.config to reference the external config file.

RazorShorts
  • 115
  • 5
0

Look at ProjA\bin\Debug. There is ProjA.exe.config file there. When you run ProjA.exe, the process read config settings from ProjA.exe.config.

For test project ProjB, it will be ProjB\bin\Debug and ProjB.dll and ProjB.dll.config.

And yes, you need to copy your config settings into ProjB\App.config file to make it work.

Sergei Zinovyev
  • 1,238
  • 14
  • 14