【问题标题】:I can't load my configuration file in my C# Application我无法在我的 C# 应用程序中加载我的配置文件
【发布时间】:2011-08-03 13:07:48
【问题描述】:

我在我的库项目中使用了一个配置文件,以便将接口与它们自己的类相关联;我遇到了麻烦,因为我的应用程序无法从配置中加载任何内容。这是配置文件中的一个示例,名为 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 的文件。但毕竟这一切我总是把键变量弄空......怎么会?到目前为止我所做的有什么问题?

【问题讨论】:

    标签: c# interface settings config


    【解决方案1】:

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

    把配置设置放到应用项目的配置文件中就可以了。

    【讨论】:

    • 好吧,我只需要我的配置文件在我的应用程序中正确加载...稍后将用作库。
    • @Dharma Dude - 配置文件的名称需要与应用程序的名称匹配。因此,如果应用程序是 example.exe,则配置文件名将是 example.exe.config
    猜你喜欢
    • 2020-04-16
    • 2021-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-07
    • 2020-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多