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 6004357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:15:08+00:00 2026-05-23T01:15:08+00:00

How to read this custom configuration from App.config? <root name=myRoot type=rootType> <element name=myName type=myType

  • 0

How to read this custom configuration from App.config?

<root name="myRoot" type="rootType">
    <element name="myName" type="myType" />
    <element name="hisName" type="hisType" />
    <element name="yourName" type="yourType" />
  </root>

Rather than this:

<root name="myRoot" type="rootType">
  <elements>
    <element name="myName" type="myType" />
    <element name="hisName" type="hisType" />
    <element name="yourName" type="yourType" />
  </elements>
  </root>
  • 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-23T01:15:09+00:00Added an answer on May 23, 2026 at 1:15 am

    To enable your collection elements to sit directly within the parent element (and not a child collection element), you need to redefine your ConfigurationProperty. E.g., let’s say I have a collection element such as:

    public class TestConfigurationElement : ConfigurationElement
    {
        [ConfigurationProperty("name", IsKey = true, IsRequired = true)]
        public string Name
        {
            get { return (string)this["name"]; }
        }
    }
    

    And a collection such as:

    [ConfigurationCollection(typeof(TestConfigurationElement), AddItemName = "test")]
    public class TestConfigurationElementCollection : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new TestConfigurationElement();
        }
    
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((TestConfigurationElement)element).Name;
        }
    }
    

    I need to define the parent section/element as:

    public class TestConfigurationSection : ConfigurationSection
    {
        [ConfigurationProperty("", IsDefaultCollection = true)]
        public TestConfigurationElementCollection Tests
        {
            get { return (TestConfigurationElementCollection)this[""]; }
        }
    }
    

    Notice the [ConfigurationProperty("", IsDefaultCollection = true)] attribute. Giving it an empty name, and the setting it as the default collection allows me to define my config like:

    <testConfig>
      <test name="One" />
      <test name="Two" />
    </testConfig>
    

    Instead of:

    <testConfig>
      <tests>
        <test name="One" />
        <test name="Two" />
      </tests>
    </testConfig>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have some custom configuration (read in from file) available throughout my
I read this post last night, and I noticed it was from 2006. I
I'm not necessarily referring to app.configs, but a custom configuration file that would store
I have a custom configuration file in my asp.net website, named urls.config , which
I've been trying to switch from using PerlSetEnv to using custom configuration directives .
I have a simple console application that is designed to read a custom Configuration
I've create a custom configuration section in my web.config file for my 3.5 web
I was playing around with how to use the Configuration Manager to read/write custom
i have a custom behavior extension which i'm using in my client side app.config
Our app depends on an external, 3rd party-supplied configuration (including custom driving/decision making functions)

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.