Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confused about .Net application settings frameworks

Being fairly new to the .Net world, I am getting very confused about where and how to store my application settings in a WPF app.

I keep seeing references to Properties.Settings.Default, but that does not resolve in my WPF app, and I cannot find what actual classes these are in order to find which assembly to pull in. Is this a WinForms only technique?

I have also found ConfigurationSettings, which appears to be deprecated, and ConfigurationManager, AppSettings, ApplicationSettings, and Settings! I'm sure many of these work together but I'm having real trouble sorting out what belongs together, and what is old, or irrelevant to WPF.

Can anyone spell out the basic options for a newbie?

like image 675
GazTheDestroyer Avatar asked Dec 11 '25 19:12

GazTheDestroyer


1 Answers

Surprised that no-one able to answer this, so I have done some more digging and will document my findings here in case anyone else is as confused as me:

  • ConfigurationSettings is dead. (<= .Net 1.1). It used to expose a set of name/value pairs via AppSettings member.

  • ConfigurationManager is the replacement (> .Net 2). It lives in System.Configuration.dll, and is the basis of all new configuration stuff. It is a static class so can be accessed anywhere. It also exposes a set of name/value pairs called AppSettings, presumably for backwards compatibility.

  • AppSettings is not type safe, it's literally pairs of strings.

  • ApplicationSettings seems to refer to ApplicationSettingsBase, which is a class used as a base for newer style type safe settings. Subclasses contain members that map to a setting. ConfigurationManageris still used to manage / serialise these.

  • Settings is a tool generated static subclass of the above that is generated by adding a "Settings File" to your project, which allows design time editing of the settings. It gets generated into the Properties namespace of your project, hence can be accessed via Properties.Settings anywhere in your app. Although WinForms is mentioned throughout the docs, it appears to be useable from WPF too.

If you don't want to use a settings file, ConfigurationManager can also be used directly using your own custom classes. Some comprehensive links for an overview of use are:

Unraveling the Mysteries of .NET 2.0 Configuration

Decoding the Mysteries of .NET 2.0 Configuration

Cracking the Mysteries of .NET 2.0 Configuration

All these settings appear to get serialsied to app.config file, although I've seen references to separate Applicationsettings files so I may be wrong about that.

like image 104
GazTheDestroyer Avatar answered Dec 13 '25 08:12

GazTheDestroyer