Night Walker
Night Walker

Reputation: 21260

app.config location problem

I have small solution, startup project dll project. In the dll project i have added app.config file, start up project doesn't have any config files. I am trying to use app config from the dll project but I am getting

"Object reference not set to an instance of an object."

I try to call it like

ConfigurationManager.ConnectionStrings["SimulatorDB"].ConnectionString;

Seems to me it is looking for the app.config of the startup project . this dll project is shared, because of it the config is sitting there.

Any idea how to solve it ? Thanks.

Upvotes: 2

Views: 233

Answers (1)

Jon Grant
Jon Grant

Reputation: 11530

When you run an executable, only the config file associated with that executable is loaded. DLLs cannot have their own config files.

When you build the solution, it will produce the following in the bin\Debug folder:

StartupApp.exe
StartupApp.exe.config (if there is one)
YourLibrary.dll

Remember this, as the Visual Studio view of things (source code) can be confusing.

Upvotes: 3

Related Questions