Reputation: 760
i am trying to read the setting from the app.config , it looks like below
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Chrome" value="path to the chrome driver" />
<add key="IE32" value="path to the IE32 driver" />
<add key="IE64" value="path to the IE64 driver" />
<add key="Url" value="url to the site"/>
</appSettings>
</configuration>
i am using the following code to read the content
using System;
using System.Configuration;
public static class Config
{
public static string ClientId
{
get
{
return ConfigurationManager.AppSettings["IE32"];
}
}
}
Why does it always return null?
Upvotes: 2
Views: 16318
Reputation: 1736
You need to set the value before you can get it. Try
public static string ClientId
{
get
{
return ConfigurationManager.AppSettings["IE32"];
}
set
{
ClientId = ConfigurationManager.AppSettings["IE32"];
}
}
Upvotes: 0
Reputation: 4572
How many projects do you have?
I suspect you have 2 projects (or more) then app.config needs to be in the project that is being run not the project with the config class.
Also when you build your project if it is a console app or a windows app the bin directory should contain a .config file with the same name as your exe. In a web app it will be in the root of the app in a file called. web.config.
Upvotes: 3