开发者

app.config location problem

开发者 https://www.devze.com 2023-03-21 02:02 出处:网络
I have small solution, startup project dll project. In the dll project i have added app.config file, start upproject doesn\'t have any config files.

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 sta开发者_如何学Crtup project . this dll project is shared, because of it the config is sitting there.

Any idea how to solve it ? Thanks.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消