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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:02:07+00:00 2026-05-25T15:02:07+00:00

I have the following bits in App.config for a .NET 3.5 Windows Service: <configSections>

  • 0

I have the following bits in App.config for a .NET 3.5 Windows Service:

<configSections>
    <section name="ConfigurationServiceSection" type="SomeApp.Framework.Configuration.ConfigurationServiceSection, SomeApp.Framework"/>
</configSections>

<ConfigurationServiceSection configSource="ConfigSections\configurationServiceSection.config" />

I’ve got this in configurationServiceSection.config:

<ConfigurationServiceSection>
    <ConfigurationServices>
        <ConfigurationService name="LocalConfig" host="localhost" port="40001" location="LON"/>
    </ConfigurationServices>
</ConfigurationServiceSection>

And here’s the code:

using System.Configuration;

namespace SomeApp.Framework.Configuration
{
    public sealed class ConfigurationServiceSection : ConfigurationSection
    {
        [ConfigurationProperty("ConfigurationServices", IsDefaultCollection = true, IsRequired = true)]
        [ConfigurationCollection(typeof(ConfigurationServices))]
        public ConfigurationServices ConfigurationServices
        {
            get
            {
                return (ConfigurationServices)base["ConfigurationServices"];
            }
        }
    }

    public sealed class ConfigurationServices : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new ConfigurationService();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            ConfigurationService configService = (ConfigurationService) element;
            return configService.Name;
        }
    }

    public sealed class ConfigurationService : ConfigurationElement
    {
        /// <summary>
        /// name
        /// </summary>
        [ConfigurationProperty("name", IsKey = true, IsRequired = true)]
        public string Name
        {
            get { return (string)this["name"]; }
            set { this["name"] = value; }
        }

        /// <summary>
        /// host
        /// </summary>
        [ConfigurationProperty("host", IsKey = false, IsRequired = true)]
        public string Host
        {
            get { return (string)this["host"]; }
            set { this["host"] = value; }
        }

        /// <summary>
        /// port
        /// </summary>
        [ConfigurationProperty("port", IsKey = false, IsRequired = true)]
        public string Port
        {
            get { return (string)this["port"]; }
            set { this["port"] = value; }
        }

        /// <summary>
        /// location
        /// </summary>
        [ConfigurationProperty("location", IsKey = false, IsRequired = true)]
        public string Location
        {
            get { return (string)this["location"]; }
            set { this["location"] = value; }
        }
    }
}

When I try to access the config with the following:

var configurationServiceSection = (ConfigurationServiceSection)configuration.GetSection("ConfigurationServiceSection");

I get this exception:

Unrecognized element 'ConfigurationService'. (C:\Code\branches\ConfigurationService\SomeApp\Src\ConfigService\SomeApp.ConfigService.WindowsService\bin\Debug\ConfigSections\configurationServiceSection.config line 3)

Everything looks in order to me?

Any ideas please? Thanks.

  • 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-25T15:02:08+00:00Added an answer on May 25, 2026 at 3:02 pm

    Ok got to the bottom of this:

    I added ‘AddItemName’ to the ConfigurationServiceSection class, as per below:

    public sealed class ConfigurationServiceSection : ConfigurationSection
    {
        [ConfigurationProperty("ConfigurationServices", IsDefaultCollection = true, IsRequired = true)]
        [ConfigurationCollection(typeof(ConfigurationServices), AddItemName = "ConfigurationService")]
        public ConfigurationServices ConfigurationServices
        {
            get
            {
                return (ConfigurationServices)base["ConfigurationServices"];
            }
        }
    }
    

    Another alternative was to override the CollectionType and ElementName properties, as per below:

    public override ConfigurationElementCollectionType CollectionType
    {
        get { return ConfigurationElementCollectionType.BasicMap; }
    }
    
    protected override string ElementName
    {
        get { return "ConfigurationService"; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In our code I have the following, for now please ignore the //* bits;
I have following fiddle: http://jsfiddle.net/BFSH4/ As you see there are two issues: The h1
I have following question on adobe omniture How we can register an iPhone app
I have installed 64 bits RHEL. I have following questions regarding ant.jar for the
I have the following struct: struct SysData { // Topic (32 bits) UTL_UINT16_Tdef SystemID:11;
I have the following data that basically I only need a few bits of
I have the following bits of code: <h:panelGroup rendered=#{userTypeController.permissionItemsUserType.contains(item)}> <h:selectBooleanCheckbox valueChangeListener=#{userTypeController.permissionChanged(this)} value=#{true}/> <h:outputText value=#{item.getAction()}
I have the following bits of code which, in my mind, seem like the
I have the following bits of code in my accountRepository public string[] GetRolesForUser(string email)
I have the following bits of code, scattered throughout my application. I'd really like

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.