2015-07-13 82 views
0

我使用System.Configuration在我的组装 但只要我实现的getter/setter方法 上的代码 被灰色的顶部System.Configuration链接(在装配不使用)System.Configuration配置管理器

配置&配置管理器得到下划线 红色是蓝绿色的。错误消息是:

找到类型和/或命名空间名称配置不能 。 (你是否缺少...等)

奇怪的是,在我的测试程序中,相同的代码 运行没有错误。有什么我需要 更改属性或程序集本身到 获取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); 
} 
+0

你是什么意思“System.Configuration链接”? – spender

回答

1

您需要添加对System.Configuration部件的参考。

+0

非常感谢你......我只是一个开始...不知何故,我必须在之前添加参考资料,并将其忘了... –

+0

不客气。请不要忘记接受答案*你*在被允许时最喜欢(在提问后15分钟后)。另请参阅[回答“已接受”时的含义是什么?](http://stackoverflow.com/help/accepted-answer)。 –

0

从您的应用程序添加的System.Configuration参考如下图所示: -

右键点击引用 - >添加引用。

选择System.Configuration它会添加所需的参考!

+0

非常感谢你......我只是一个开始...不知何故,我必须在之前添加引用并忘记它... –

+0

很高兴它帮助你! – Neel