Reading from a app.config file

app-config, c#

Solution

below code gives you the content of active config file.

var content  = File.ReadAllLines(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);

Check what you get as `content`, is it contain `key="name" value="Chan"` or something else ?

if you given `<add key="name" value="Chan" />` then ConfigurationManager.AppSettings["name"] should return as `Chan`

Problem

I am trying to print to `Console.Write` the value of the key `name` from the following `app.config` file. ``` <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="name" value="Chan" /> </appSettings> </configuration> ``` C# code : ``` Console.Write(ConfigurationManager.AppSettings["name"]); ``` Nothing gets printed in the console. Why is this ? Note: I have added a reference to the `System.Configuration` dll

Original source

Related problems