Skip to content
Fix Code Error

Reading settings from app.config or web.config in .NET

March 13, 2021 by Code Error
Posted By: Anonymous

I’m working on a C# class library that needs to be able to read settings from the web.config or app.config file (depending on whether the DLL is referenced from an ASP.NET web application or a Windows Forms application).

I’ve found that

ConfigurationSettings.AppSettings.Get("MySetting")

works, but that code has been marked as deprecated by Microsoft.

I’ve read that I should be using:

ConfigurationManager.AppSettings["MySetting"]

However, the System.Configuration.ConfigurationManager class doesn’t seem to be available from a C# Class Library project.

What is the best way to do this?

Solution

You’ll need to add a reference to System.Configuration in your project’s references folder.

You should definitely be using the ConfigurationManager over the obsolete ConfigurationSettings.

Answered By: Anonymous

Related Articles

  • error LNK2005: ✘✘✘ already defined in…
  • How to find Control in TemplateField of GridView?
  • How to avoid a System.Runtime.InteropServices.COMException?
  • ComboBox.SelectedItem giving Null value
  • How do I install soap extension?
  • Error Message : Cannot find or open the PDB file
  • Error Stack Overflow when trying to hide buttons in…
  • Error: the entity type requires a primary key
  • How can I specify a [DllImport] path at runtime?
  • Get operating system info
  • Displaying Total in Footer of GridView and also Add…
  • Trying to Call Multiple ActionCreators in Component…
  • Vue.js exclude settings file from being bundled
  • Multithreading: waiting for a thread to finish so I…
  • C#WPF ConfigurationManager.AppSettings Only…
  • Compile a DLL in C/C++, then call it from another program
  • How to read AppSettings values from a .json file in…
  • ConfigurationManager.AppSettings - How to modify and save?
  • Getting value from appsettings.json in .net core
  • MSBuild doesn't copy references (DLL files) if using…
  • How to use ConfigurationManager
  • How can I find the product GUID of an installed MSI setup?
  • Detect if Visual C++ Redistributable for Visual…
  • The type or namespace name 'System' could not be found
  • Could not load file or assembly 'Newtonsoft.Json' or…
  • Visual Studio debugging/loading very slow
  • Serilog config in appsettings.json for an ASP.NET…
  • .Net picking wrong referenced assembly version
  • What are the undocumented features and limitations…
  • ASP.NET Core configuration for .NET Core console application
  • How do I control c++ DLL debug symbols loading?
  • Polymer element with javascript dependencies
  • How to extract an assembly from the GAC?
  • Add values to app.config and retrieve them
  • Getting "error": "unsupported_grant_type" when…
  • Logging best practices
  • Equivalent to 'app.config' for a library (DLL)
  • Aurelia bundling issue with virtual directory
  • Chart creating dynamically. in .net, c#
  • How can I use a reportviewer control in an asp.net…
  • Qt 5.1.1: Application failed to start because…
  • Configuration Error: ASP.NET MVC3
  • How to check if an appSettings key exists?
  • How do you read from appsettings.json in the same…
  • Using app.config in .Net Core
  • Attempted to read or write protected memory
  • Where does error CS0433 "Type 'X' already exists in…
  • How should I deal with "package '✘✘✘' is not…
  • What are the currently supported CSS selectors…
  • The type or namespace name does not exist in the…
  • C# .NET5 Web React app - Publish only for…
  • How to add Typescript to a Nativescript-Vue project?
  • How can I save application settings in a Windows…
  • Text size and different android screen sizes
  • How to add a reference programmatically
  • How to fix "Referenced assembly does not have a…
  • Could not load file or assembly…
  • How to aggregate data in a Pandas Pivot Table?
  • CRUD - Create select dropdown list autofills another…
  • Dynamically load a function from a DLL
  • What exactly are DLL files, and how do they work?
  • Register DLL file on Windows Server 2008 R2
  • How to use a App.config file in WPF applications?
  • How to fix "The ConnectionString property has not…
  • Ubuntu apt-get unable to fetch packages
  • What is a NullReferenceException, and how do I fix it?
  • Cannot find control with name: formControlName in…
  • Loading DLLs at runtime in C#
  • Select Tag Helper in ASP.NET Core MVC
  • What is the correct way to setup CORS with ASP.NET…
  • How to use the ConfigurationManager.AppSettings
  • Could not load file or assembly "Oracle.DataAccess"…
  • ASP.NET Web Site or ASP.NET Web Application?
  • asp.net: Invalid postback or callback argument
  • How to Call Method Only if LIbrary Exists
  • The type initializer for…
  • Get ConnectionString from appsettings.json instead…
  • How do I build an import library (.lib) AND a DLL in…
  • Iterator invalidation rules
  • How can I center all my contents in html?
  • Calculating score on a quiz test using asp.net C#…
  • What are the best JVM settings for Eclipse?
  • Can Windows Containers be hosted on linux?
  • Where can I find a NuGet package for upgrading to…
  • Reading a key from the Web.Config using ConfigurationManager
  • AppCompat v7 r21 returning error in values.xml?
  • How to get a List collection of values from…
  • Why am I getting a "401 Unauthorized" error in Maven?
  • Sorting a filtered list
  • C++ template,typename and operator
  • What does do?
  • Why widget EmailInput style doesn't apply
  • Aurelia Windows Authentication - Post 401 Unauthorized
  • Invoke or BeginInvoke cannot be called on a control…
  • Modifying User data in ASP.NET Core MVC
  • how to call an ASP.NET c# method using javascript
  • Page or Form Not showing validation Error Django
  • How to add "on delete cascade" constraints?
  • NLog ApplicationInsightsTarget unable to read…
  • C# Error "The type initializer for ... threw an exception

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How can I generate an MD5 hash?

Next Post:

Deleting DataFrame row in Pandas based on column value

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error