ConfigurationManager.AppSettings[“SettingName”] vs Properties.Settings.Default.SettingName when should I use each?

StackOverflow https://stackoverflow.com/questions/1914265

  •  19-09-2019
  •  | 
  •  

Question

What should dictate when I should use the configurationManager.AppSettings or the strongly typed settings that visual studio generates? The strongly typed ones seem much more appropriate in most cases, but I suppose that it would be possible to add settings dynamically to a deployed application using the ConfigurationManager approach, but are there any guidelines under which circumstances each is designed to be used?

Was it helpful?

Solution

From what I read, looks like AppSettings is the older way of doing things. MSDN docs states that user settings can be written at run time if you are using settings.

I always prefer strongly typed settings, which can be implemented with ConfigSection handlers.

Pros and cons of appSettings vs applicationSettings (.NET app.config)

OTHER TIPS

The biggest difference is that the generated properties are readonly, so the main reason to use AppSettings is if you want to write them (which is rare).

And yes, you could use AppSettings for dynamicaly generated settings but that is rare too.

Use Properties.Settings.Default.SettingName. But ConfigurationManager.AppSettings[”SettingName”] should be used only when first is impossible to use.

I'd advise that the loosely typed settings are older and really should only be used for backwards compatibility.

The strongly-typed settings are more robust as they are... strongly typed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top