Class Library reading web.config Settings OR app.config settings

Joined
Sep 16, 2008
Messages
2
Reaction score
0
I have a web application and a console application that both reference the same class library. The class library needs to read a config file for some custom configuration info.

When running with the windows app, I use the following to define my Configuration:

Configuration appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

But, with the web app, I use this instead:

Configuration appConfig = WebConfigurationManager.OpenWebConfiguration("\\web.config");

I don't want two versions of the class library, is there a way for it to open the configuration file that will work the same in both instances? If I use the ConfigurationManager option with the web application, I get the following error:
Value does not fall within the expected range.
at this line:
CustomConfig customConfig = (CustomConfig)appConfig.GetSection("CustomConfig");

I'm using C# and .NET framework 2.0
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top