App.config 中的配置未正确提取 [英] Configuration from App.config isn't being pulled correctly

查看:36
本文介绍了App.config 中的配置未正确提取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试提取我保存到 app.config 文件的 URL,但它返回一个空白字符串.任何想法为什么?

I'm trying to extract a URL I saved to the app.config file, but it's returning a blank string. Any ideas why?

string asdf = String.Format("{0}", ConfigurationManager.AppSettings["MemberUrl"]);

和配置文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="ForumUrl" value="http://www.dreamincode.net/forums/xml.php?showforum=" />
    <add key="MemberUrl" value="http://www.dreamincode.net/forums/xml.php?showuser=" />
  </appSettings>
</configuration>

推荐答案

你的类库需要的所有配置信息都必须在主项目 App.config 或 web.config 中.换句话说,如果您的 app.config 文件附加到库中,它将不会被读取.

All config information that your class library needs must be in the main projects App.config or web.config. In other words, if your app.config file is attached to the library it will NOT be read.

转到主应用程序并将适当的键/值添加到其配置文件中.

Go to the main application and add the appropriate keys/values to it's config file.

这篇关于App.config 中的配置未正确提取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆