AppSettings get value from .config file

I’m not able to access values in configuration file. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var clientsFilePath = config.AppSettings.Settings[“ClientsFilePath”].Value; // the second line gets a NullReferenceException .config file: <?xml version=”1.0″ encoding=”utf-8″ ?> <configuration> <appSettings> <!– … –> <add key=”ClientsFilePath” value=”filepath”/> <!– … –> </appSettings> </configuration> Do you have any suggestion what should I do? 16 Answers 16

Getting value from appsettings.json in .net core

Not sure what am I missing here but I am not able to get the values from my appsettings.json in my .net core application. I have my appsettings.json as: { “AppSettings”: { “Version”: “One” } } Startup: public class Startup { private IConfigurationRoot _configuration; public Startup(IHostingEnvironment env) { _configuration = new ConfigurationBuilder() } public void … Read more

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

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 … Read more