【发布时间】:2011-12-29 09:56:32
【问题描述】:
我编写了一个 C# 项目,我配置了 app.config 文件如下:
<appSettings>
<add key="smUserName" value= "XXX"/>
<add key="smPassword" value= "XXX"/>
</appSettings>
但是我无法从 app.config 中获取 smUserName 和 smPassword 值:
using System.Configuration;
// more code snipped...
public static string smUserName = ConfigurationManager.AppSettings.Get("smUserName").ToString();
public static string smPassword = ConfigurationManager.AppSettings.Get("smPassword").ToString();
尽管有using System.Configuration 语句,编译此代码会给出错误“当前上下文中不存在名称'ConfigurationManager'”。
【问题讨论】:
-
试试
ConfigurationManager.AppSettings["smUserName"]和ConfigurationManager.AppSettings["smPassword"] -
您遇到了哪个错误?运行时错误,或者项目没有编译?
-
错误是什么,很可能是错误在告诉你问题是什么!
-
错误是“当前上下文中不存在名称'ConfigurationManager'”
标签: c# web-services app-config console-application