0

I am using System.Configuration in my assembly, but as soon as I implement the getter/setters the System.Configuration link on top of the code gets greyed out (for not used in the assembly)

Configuration & the ConfigurationManager get underlined red instead of teal color. Error message is :

The type and/or namespace name Configuration could not be found. (Are you missing... etc.)

Strange thing is, in my test program the same code runs without errors. Is there anything I need to change in the properties or the assembly itself to get System.Configuration running?

Thank you for your help!

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);
}
R.J. Dunnill
  • 2,049
  • 3
  • 10
  • 21
mb-nem
  • 1
  • 1

2 Answers2

1

You need to add a reference to the System.Configuration assembly.

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
  • Thank You so much... i am just a beginning... somehow magically i must have added the reference before and forgot about it... – mb-nem Jul 13 '15 at 12:17
  • You are welcome. Please don't forget to accept the answer *you* liked best when allowed to (after 15 minutes after your question was asked). Also see [What does it mean when an answer is "accepted"?](http://stackoverflow.com/help/accepted-answer). – Patrick Hofman Jul 13 '15 at 12:19
0

Add reference of System.Configuration from your application as shown below :-

Right click on References --> Add Reference.

Select System.Configuration and it will add the required reference!

Neel
  • 11,625
  • 3
  • 43
  • 61
  • Thank You so much... i am just a beginning... somehow magically i must have added the reference before and forgot about it... – mb-nem Jul 13 '15 at 12:17