Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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 to access app.config
C#
ConfigurationSettings.AppSettings["conStr"].ToString();
---> this is returning null value
Also when i try to use ConfigurationManager it says not found or missing assembly reference.

C#
using System.Configuration
is also added .
Posted
Updated 20-Nov-12 7:04am
v3
Comments
Herman<T>.Instance 20-Nov-12 8:17am    
is the dll in the BIN folder? Add an app.config to that folder and add your key.
MT_ 20-Nov-12 8:54am    
Did you check solutions below. You need to put it in web.config.

If it is a web application, then you need to put the key in the web.config (under AppSettings) node.
All the class libraries used in web application will have access to web.config keys.

For ConfigurationManager, you will need to add a reference manually and also add a namespace
C#
using System.Configuration;


Hope that helps
Milind
 
Share this answer
 
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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900