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

Discussion in '.NET' started by leeanne, Sep 24, 2008.

  1. leeanne

    leeanne

    Joined:
    Sep 16, 2008
    Messages:
    2
    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
    leeanne, Sep 24, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QXVndXN0aW4gUHJhc2FubmEuIEo=?=

    Web.Config Get Config settings at runtime.

    =?Utf-8?B?QXVndXN0aW4gUHJhc2FubmEuIEo=?=, Feb 5, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,257
    Kevin Spencer
    Feb 6, 2004
  2. Tony Jones
    Replies:
    2
    Views:
    13,158
    Martin Marinov
    Jun 30, 2004
  3. CSharpner
    Replies:
    0
    Views:
    1,021
    CSharpner
    Apr 9, 2007
  4. donet programmer
    Replies:
    3
    Views:
    1,539
    Gregory A. Beamer
    Nov 20, 2009
  5. Yamagami
    Replies:
    0
    Views:
    193
    Yamagami
    Feb 16, 2007
Loading...

Share This Page