开发者

.net library does not pick keys from app.config

开发者 https://www.devze.com 2023-02-25 12:24 出处:网络
I am working on a error reporting library in c#, and its a static class. When I am running this library from other applications by adding a reference. It does not pick the AppSetting Keys from app.co

I am working on a error reporting library in c#, and its a static class. When I am running this library from other applications by adding a reference. It does not pick the AppSetting Keys from app.config.

In that case I need to add the keys to all main applications to make it working.

Are their any other solution to sortout this problem?

Thanks 开发者_开发知识库and Regards


If you mean in your library you have an app.config file with values and when you use your library in other applications, the value is not loaded then it is by design.

Only the config file is loaded whose name is "exe name" + ".exe" or web.config in web applications.

You need to copy the appSettings to the EXE application's app.config. Or use alternate configuration for your application.

It is also by design since libraries must take their configuration from their clients.


As an alternative to the app.config, if your library needs it's own configuration, or if you just don't want to use app.config, you can use a Settings file instead of rolling your own. Here is an overview, this is a bit old, but works the same way.

http://msdn.microsoft.com/en-us/library/aa730869.aspx


That is correct. When you develop an library, you need to configure the AppSettings keys in the main application that uses the library.

You should always have default values or throw an exception right away, if there is no value configure (the option that suites better for you).

You can use Settings, I think that will "pick" the values of the library and you can overrite this in the main application also.

0

精彩评论

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