我在程序集中使用System.Configuration,但一旦实现getter/getter,代码顶部的System.Configuration链接就会变灰(因为没有在程序集中使用)。
Configuration & ConfigurationManager以带下划线的红色代替teal颜色。错误信息是:
无法找到类型和/或命名空间名称配置。(你失踪了吗.等)
奇怪的是,在我的测试程序中,相同的代码运行时没有错误。要运行System.Configuration,需要更改属性或程序集本身吗?
谢谢你的帮助!
public string getAppSetting(string key)
{
//Load AppSettings
Configuration config = ConfigurationManager.
OpenExeConfiguration(
System.Reflection.Assembly.
GetExecutingAssembly().Location);
//Zurückgeben der dem Key zugehörigen Value
return config.AppSettings.Settings[key].Value;
}
public void setAppSetting(string key, string value)
{
//Save AppSettings
Configuration config = ConfigurationManager.
OpenExeConfiguration(
System.Reflection.Assembly.
GetExecutingAssembly().Location);
//Überprüfen ob Key existiert
if (config.AppSettings.Settings[key] != null)
{
//Key existiert. Löschen des Keys zum "überschreiben"
config.AppSettings.Settings.Remove(key);
}
//Anlegen eines neuen KeyValue-Paars
config.AppSettings.Settings.Add(key, value);
//Speichern der aktualisierten AppSettings
config.Save(ConfigurationSaveMode.Modified);
}发布于 2015-07-13 12:07:33
您需要添加对System.Configuration程序集的引用。
发布于 2015-07-13 12:08:36
从您的应用程序中添加System.Configuration引用,如下所示:
右击引用->添加引用。
选择System.Configuration,它将添加所需的引用!
https://stackoverflow.com/questions/31382942
复制相似问题