我无法在 C# 应用程序中加载配置文件

发布于 2024-11-27 20:04:49 字数 967 浏览 2 评论 0原文

我在库项目中使用配置文件,以便将接口与其自己的类相关联;我遇到了麻烦,因为我的应用程序无法从配置加载任何内容。以下是配置文件的示例,该文件名为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

归属感 2024-12-04 20:04:49

库项目没有自己的配置 - 它们使用使用该库的应用程序中的配置。

将配置设置放入应用程序项目的配置文件中,应该没问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文