tags:

views:

1267

answers:

4

Can someone please explain to me the difference between the AppSettings and ApplicationSettings sections in the App.Config file. Why are there two different sections that apparently do the same thing??

A: 

This looks like a shade of a previous question:

http://stackoverflow.com/questions/460935/pros-and-cons-of-appsettings-vs-applicationsettings-net-app-config

and there is some help here as well: http://forums.asp.net/t/1124253.aspx and a long explanation here: http://msmvps.com/blogs/windsor/archive/2007/01.aspx

Irwin
+1  A: 

http://kevinskorner.net/blog/post/2008/03/27/applicationSettings-vs-appSettings.aspx

Application settings give us more control and most important, intelliscence.

Matthew Vines
+1  A: 

It's to do with backwards compatibility, which we all love. ApplicationSettings is the newer construct.

User the newer ConfigurationManager and WebConfigurationManager classes to get at your settings now and to do this you need a reference so System.configuration and not System.Configuration :).

At one point it started to get a bit silly didn't it.

Robert
+1  A: 

I believe that the <appsettings/> collection in your app.config/web.config allows you to store settings in key-value pairs, and is accessed through the System.Configuration API, as follows:

string setting = System.Configuration.ConfigurationSettings.AppSettings["settingName"];

Settings can only be stored and retrieved as string values. The above way of doing things has been deprecated.

The <ApplicationSettings/> collection in your config file stores your settings in a strongly typed manner, and also allows you to access these settings in a strongly typed way. VS automatically generates wrapper classes for you, in the settings.settings file in the Properties folder of your project. To add a settings file to your project, right click on your project, and click Properties, then open the Settings tab. Then click the link to add a new settings file. VS will automatically generate one for you. It's that easy.

You usually access your settings as follows:

MyProjectName.Properties.Settings.Default.SettingName

Notice the difference in how the two collections are accessed.

The second (non-deprecated) way of storing settings is the better way to do it, and provides lots of flexibility and power. It takes some learning though - but it is worth the effort.

Saajid Ismail
"The above way of doing things has been deprecated." - System.Configuration.ConfigurationSettings.AppSettings has been deprecated, but it's replaced by System.Configuration.ConfigurationManager.AppSettings. The use of the <appSettings> configuration section has not been deprecated.
Joe
Ahh right! Thanks for that clarification.
Calanus