mb-nem
mb-nem

Reputation: 1

System.Configuration Configuration Manager

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);
}

Upvotes: 0

Views: 1217

Answers (2)

Neel
Neel

Reputation: 11721

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!

Upvotes: 0

Patrick Hofman
Patrick Hofman

Reputation: 156918

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

Upvotes: 1

Related Questions