Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6924601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:41:00+00:00 2026-05-27T10:41:00+00:00

I have some code in a class library built to target the .Net Framework

  • 0

I have some code in a class library built to target the .Net Framework 4 Client Profile. The code accesses the configuration of the consuming applications. For client apps (WinForms apps, console apps, etc.) getting the right object for App.Config is easy:

ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

My class library also needs to work for web applications. The proper way to get access to Web.Config is also easy:

WebConfigurationManager.OpenWebConfiguration("~");

The problem is that WebConfigurationManager is part of System.Web which is not available as part of the .Net Framework 4 Client Profile.

Is there a way I can write my code or structure my project so that it will work in both cases? It needs to run well enough to access app.config on systems that only have the client profile installed. It also needs to be able to access web.config when necessary. Perhaps there’s some way I can dynamically load system.web or another assembly when it is available and when it is needed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:41:01+00:00Added an answer on May 27, 2026 at 10:41 am

    As mentioned by Davide Piras, ConfigurationManager.AppSettings[] will work for the entries that are in the AppSettings section. Outside of that section, ConfigurationManager.GetSection() can be used.

    Strangely, the return value on ConfigurationManager.GetSection() isn’t the same as the return value on Configuration.GetSection(). The ConfigurationManager version doesn’t return an object that you can cast to an AppSettingsSection or whatever. Instead you have to cast it to a System.Collections.Specialized.NameValueCollection. However, as long as you only are looking to work with key/value strings it works well enough. The complete code looks like this:

    using System.Configuration;
    using System.Collections.Specialized;
    
    var settingsSection = ConfigurationManager.GetSection(sectionName) as NameValueCollection;
    var configValue = settingsSection[keyName];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a class library in VB .NET. Some code in the library
What exactly are the Python scoping rules? If I have some code: code1 class
Let's say I have some Java code: public class SomeClass { static { private
I have some code that will be accessed from two threads: class Timer{ public:
Say I have some code like namespace Portal { public class Author { public
I have some C++ code #include <cstdio> #include <boost/bind.hpp> #include <boost/function.hpp> class A {
I have some code for starting a thread on the .NET CF 2.0: ThreadStart
In some library code, I have a List that can contain 50,000 items or
I have built a Library project (DLL) in .NET. And sometimes I use the
I have a libfoo.so library built from C++ code (compiled with gcc), and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.