2015-07-13 93 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