App.config in a C# Class Library
I have a class library that has the following App.config file in it.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Problem is, that when I attempt to get the eventLogName key value my class object like this:
-------------------------------------------------------------------------------
ConfigurationSettings.AppSettings["eventLogName"].ToString()
-------------------------------------------------------------------------------
It doesn't see the appSettings as having any keys at all.
I see the connectionStrings key, just not the appSettings key
weird....
thanks
doug

App.config in a C# Class Library
EricGeorge
Hello,
I have one class library, and I tried to access some appSettings that I have on my web.config file. But I didn't succeed.
This is the code I have in my class library:
using System.Configuration;
protected static string strApp = "";
...
public static string retAPPNAME()
{
strApp = ConfigurationSettings.AppSettings["APPNAME"];
return strApp;
}
...
And, when I try to get the value back, I do this:
string
strAppnames = MyClass.retAPPNAME();But I always got a null value.
What I'm doing wrong
Garrett - MSFT
Nope.
ConfigurationManager.AppSettings.Count=0.
I can't figure it out!
DocMARs
Class libraries use the config file from the application that utilizes them not the app.config file that may be in their projects. So make sure the config file from the application that references the library has all the keys in it the library needs.
K_L
Please remove the element <clear/>, which instructs the configuration manager to clear up previous config settings
.
Hope this may help.
Cheers
Karin Huber
I forgot to include the appSettings key into the web.config file.
Thank you.