我无法在 C# 应用程序中加载配置文件
我在库项目中使用配置文件,以便将接口与其自己的类相关联;我遇到了麻烦,因为我的应用程序无法从配置加载任何内容。以下是配置文件的示例,该文件名为 app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Sic2Lib.it.carrefour.sic.profiler.datasource.def.AuthenticateDS" value="Sic2Lib.it.carrefour.sic.profiler.datasource.impl.AuthenticateDSImpl"/>
<add key="Sic2Lib.it.carrefour.sic.profiler.datasource.def.CheckUserDS" value="Sic2Lib.it.carrefour.sic.profiler.datasource.impl.CheckUserDSImpl"/>
<add key="Sic2Lib.it.carrefour.sic.profiler.datasource.def.ReadApplicationConfigDS" value="Sic2Lib.it.carrefour.sic.profiler.datasource.impl.ReadApplicationConfigDSImpl"/>
它保存在 DataSourceFactory 类的同一目录中。此类应该通过命令进行设置,
NameValueCollection keys = ConfigurationManager.AppSettings;
因此,我构建的项目没有错误,并且在 bin/Debug 文件夹中得到了一个名为 myProject.dll.confing 的文件。但毕竟我总是把keys变量弄空......怎么会呢?到目前为止我所做的有什么问题吗?
I'm using a config file in my Library project in order to associate the interfaces with their own classes; I'm having troubles since my Application can't load anything from the config. Here is a sample from the config file,which is called app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Sic2Lib.it.carrefour.sic.profiler.datasource.def.AuthenticateDS" value="Sic2Lib.it.carrefour.sic.profiler.datasource.impl.AuthenticateDSImpl"/>
<add key="Sic2Lib.it.carrefour.sic.profiler.datasource.def.CheckUserDS" value="Sic2Lib.it.carrefour.sic.profiler.datasource.impl.CheckUserDSImpl"/>
<add key="Sic2Lib.it.carrefour.sic.profiler.datasource.def.ReadApplicationConfigDS" value="Sic2Lib.it.carrefour.sic.profiler.datasource.impl.ReadApplicationConfigDSImpl"/>
Which is held in the same directory of the DataSourceFactory Class. This class is supposed to take the setting through the command
NameValueCollection keys = ConfigurationManager.AppSettings;
So, I build the project with no errors and I get a file called myProject.dll.confing in the bin/Debug folder. But after all this I always get the keys variable empty...How come? What's wrong with what I've done so far?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
库项目没有自己的配置 - 它们使用使用该库的应用程序中的配置。
将配置设置放入应用程序项目的配置文件中,应该没问题。
Library projects do not have their own configuration - they use the configuration from the application that uses the library.
Put the configuration settings in the configuration file of the application project and you should be fine.