Referencing ConfigurationManager

When I started working in VS2005, I assumed that accessing your AppSettings would be the same as it was in VS2003. On compiling, the IDE served up the following warning.

'System.Configuration.ConfigurationSettings.AppSettings' is obsolete: 'This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings'

Old way of accessing AppSettings

string mySetting = ConfigurationSettings.AppSettings["mySetting"];

New way of accessing AppSettings

string mySetting = ConfigurationManager.AppSettings["mySetting"];

So I changed my code accordingly, but the project wouldn't compile. It turns out that you need to add a reference to System.Configuration to the project, rather than simply adding it with a using statement. This can be done as follows.

Add a reference to System.Configuration by clicking Project -> Add Reference... and searching through the .NET components for System.Configuration

Author Barrington Haynes

I have nothing more to say

Add Comment

Name
Comment
 

Your comment has been received and will be shown once it passes moderation.