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

  • Home
  • SEARCH
  • 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 511267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:11:56+00:00 2026-05-13T07:11:56+00:00

Solution: Just to add the solution: sectionGroups do not seem to have attributes. The

  • 0

Solution: Just to add the solution: sectionGroups do not seem to have attributes. The proper way seems to have a ConfigurationSection as the parent and ConfigurationElement as each children. There is also ConfigurationElementCollection for Collections. An example from the .net Framework: <roleManager> is a Section, <providers> is an ElementCollection. I blogged about my solution.

Original Question: I have a custom sectionGroup in my web.config:

<sectionGroup name="myApp" type="MyApp.MyAppSectionGroup">
  <section name="localeSettings" 
           type="MyApp.MyAppLocaleSettingsSection"/>
</sectionGroup>

The sectionGroup itself is supposed to have an attribute:

<myApp defaultModule="MyApp.MyAppTestNinjectModule">
  <localeSettings longDateFormat="MM/dd/yyyy HH:mm:ss" />
</myApp>

I have trouble accessing that attribute (defaultModule). Getting a section is very easy using ConfigurationManager.GetSection("myApp/localeSettings") and casting it to a class that inherits from ConfigurationSection.

But I can’t seem to easily access the sectionGroup, as ConfigurationManager.GetSection("myApp") returns null. I’ve tried ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).SectionGroups["myApp"], but this does not implement an indexer that gives me access to defaultModule.

Am I misunderstanding something? Are sectionGroups really only Containers with no settings of their own? Can I nest sections without having a sectionGroup at all? And is OpenExeConfiguration appropriate for .net applications (with web.config) or is it just for app.config’s?

Edit: Thanks for the hint regarding WebConfigurationManager instead of ConfigurationManager. That doesn’t solve my main problem, but at least this has more sensible named OpenXXX methods.

At the moment, these are the two classes. The LocaleSettings works perfectly fine, just the SectionHandler doesn’t let my access the “defaultModule” attribute.

public class MyAppSectionGroup: ConfigurationSectionGroup
{
    [ConfigurationProperty("localeSettings")]
    public MyAppLocaleSettingsSection LocaleSettings
    {
        get
        {
            return Sections["localeSettings"] as MyAppLocaleSettingsSection;
        }
    }
}

public class MyAppLocaleSettingsSection: ConfigurationSection
{
    [ConfigurationProperty("longDateFormat", DefaultValue = "yyyy-MM-dd HH:mm")]
    public string LongDateFormat
    {
        get
        {
            return this["longDateFormat"] as string;
        }
    }
}
  • 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-13T07:11:57+00:00Added an answer on May 13, 2026 at 7:11 am

    Almost all you’re trying to do should be possible and should be ok and legal – you must be missing something small, I guess. The only thing I’m not sure of is whether section groups can have attributes of their own – they might be designed as being just containers for sections, which then have the actual config data in them…

    For accessing the web.config, you should also try to use the WebConfigurationManager instead of the “straight” ConfigurationManager (that’s for app.config files).

    Can you show us the code for your MyApp.MyAppSectionHandler and MyApp.MyAppLocaleSettingsConfigurationSection ?

    Have you checked out Jon Rista’s three-part series on .NET 2.0 configuration up on CodeProject? It’s an excellent intro to how to use and extend the .NET config system – highly recommended, and most useful indeed!

    • Unraveling the mysteries of .NET 2.0 configuration
    • Decoding the mysteries of .NET 2.0 configuration
    • Cracking the mysteries of .NET 2.0 configuration

    If you’re dealing with custom config sections, I would also recommend you have a look at the Configuration Section Designer, a Visual Studio plug-in that allows you to visually define your config section groups and config sections and the attributes and their datatypes in those sections – great time saver and educational tool!

    Some more digging has shown:

    • you could potentially define [ConfigurationProperty] on a custom config section group, but there is no automatic “backing store” for those properties, and I can’t see any way of hooking into the loading of the XML from the config file, either – so I guess the section groups really are only containers
    • you can nest section groups within one another, but the leaf level has to be a configuration section, and those cannot be nested in anything but a config section group.

    Marc

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 502k
  • Answers 502k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer for(int i=0; i < [listOfItems count]; ++i) { Restaurant* r… May 16, 2026 at 2:28 pm
  • Editorial Team
    Editorial Team added an answer I am trying to access a link A passing the… May 16, 2026 at 2:28 pm
  • Editorial Team
    Editorial Team added an answer look on this : http://flowplayer.org/tools/demos/combine/portfolio/index.html# May 16, 2026 at 2:28 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I created an Add-in project and now I have this in my solution explorer:
this is probably a simple solution I am not that familiar with C just
Is it a good practice to create another project in your solution just to
I had been happily coding along on a decent sized solution (just over 13k
Currently I have solution A that contains a domain layer base and solution B
I need to add dynamicaly Components to JPanel, but if i make just add(Component)
I just upgraded a VS 2008 solution containing WinForms, general use libraries, and a
I have a long list e2i, which maps rownames to values, and has duplicate
I'm looking for a simple to setup and to use solution to test the
In a project I am working on, I just finished writing an XSD for

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.