Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access the app.config value in the class library?

Tags:

c#

asp.net

I have a web application which is using a dll of a class library. I am unable to access the app.config value in the class library

How I'm trying to access app.config:

ConfigurationSettings.AppSettings["conStr"].ToString();

this is returning a null value

Also when I try to use ConfigurationManager it says not found or missing assembly reference.

using System.Configuration is also added .

like image 320
user1838404 Avatar asked Nov 20 '12 13:11

user1838404


2 Answers

You must put the AppSettings value inside the web.config of the application, because it override the app.config from the class library.

Add a reference to System.Configuration namespace in the class library project, them get the value you're expecting from the web.config file, not from the app.config file.

like image 123
Marlon Vidal Avatar answered Sep 29 '22 16:09

Marlon Vidal


Add a reference to the System.Configuration library in your project, then get your key like this

ConfigurationManager.AppSettings["conStr"]

Notice that a web application will search for a web.config file and not an app.config!

like image 30
AMember Avatar answered Sep 29 '22 16:09

AMember