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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:06:23+00:00 2026-05-13T08:06:23+00:00

I have the following code var section = new CustomConfigurationSection(); section.SectionInformation.Type = System.Configuration.NameValueFileSectionHandler; section.SectionInformation.SetRawXml(sectionXml);

  • 0

I have the following code

var section = new CustomConfigurationSection();
section.SectionInformation.Type = "System.Configuration.NameValueFileSectionHandler";
section.SectionInformation.SetRawXml(sectionXml);
configuration.Sections.Add(sectionName, section);

last line of which throws:

ConfigurationErrorsException An error
occurred executing the configuration
section handler for monitor.

with the inner exception:

Unrecognized element ‘screens’. (line
1) (line 1)

Definition of CustomConfigurationSection:

public class CustomConfigurationSection: ConfigurationSection
{
    public CustomConfigurationSection()
    {
    }
}

configuration is an instance of a custom class, which has a property named Sections, that have the type ‘ConfigurationSectionCollection’.

And the incoming xml in sectionXml is:

<monitor>
  <screens>
    <screen>
      <regions>
        <region>
          <labelCoordinates />
          <startupApplication>Internet</startupApplication>
          <color />
          <width>426</width>
          <height>266</height>
          <x1>0</x1>
          <x2>0</x2>
          <y1>0</y1>
          <y2>0</y2>
        </region>
      </regions>
      <height>800</height>
      <width>1280</width>
    </screen>
    <screen>
      <regions />
      <height>0</height>
      <width>0</width>
    </screen>
  </screens>
</monitor>

How can I get this to work?

  • 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-13T08:06:23+00:00Added an answer on May 13, 2026 at 8:06 am

    After looking at your example one reason I can see that it won’t work is you are using the NameValueFileSectionHandler. If I remember correctly this only allows the following syntax:

    <YourSectionName>
      <add key="monitor.region.x" value="0"/>
    <YourSectionName>
    

    Based on the xml you are wanting to use you probably need to fully implement the config section classes. So you would have something like the following:

    class ServiceResponseSection : ConfigurationSection
    {
        [ConfigurationProperty("ServiceResponses")]
        [ConfigurationCollection(typeof(ServiceResponse), AddItemName = "addServiceResponse", RemoveItemName = "removeServiceResponse", ClearItemsName = "clearServiceResponses")]
        public ServiceResponses ServiceResponses
        {
            get { return this["ServiceResponses"] as ServiceResponses; }
        }
    
    }
    
    public class ServiceResponses : ConfigurationElementCollection
    {
        public override ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return ConfigurationElementCollectionType.AddRemoveClearMap;
            }
        }
    
        public ServiceResponse this[int index]
        {
            get
            {
                return (ServiceResponse)this.BaseGet(index);
            }
            set
            {
                if (this.BaseGet(index) != null)
                {
                    this.BaseRemoveAt(index);
                }
                this.BaseAdd(index, value);
            }
        }
    
        public new ServiceResponse this[string responseString]
        {
            get
            {
                return (ServiceResponse)this.BaseGet(responseString);
            }
            set
            {
                if (this.BaseGet(responseString) != null)
                {
                    this.BaseRemoveAt(this.BaseIndexOf(this.BaseGet(responseString)));
                }
                this.BaseAdd(value);
            }
        }
    
        public void Add(ServiceResponse ServiceResponse)
        {
            this.BaseAdd(ServiceResponse);
        }
    
        public void Clear()
        {
            this.BaseClear();
        }
    
        protected override ConfigurationElement CreateNewElement()
        {
            return new ServiceResponse();
        }
    
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((ServiceResponse)element).ResponseString;
        }
    
        public void Remove(ServiceResponse element)
        {
            BaseRemove(element.ResponseString);
        }
    
        public void Remove(string responseString)
        {
            BaseRemove(responseString);
        }
    
        public void RemoveAt(int index)
        {
            BaseRemoveAt(index);
        }
    
    }
    
    public class ServiceResponse : ConfigurationElement
    {
        private int m_tryCount;
    
        public ServiceResponse()
        {
            this.m_tryCount = 0;
        }
    
        [ConfigurationProperty("responseString")]
        public string ResponseString
        {
            get { return (String)this["responseString"]; }
            set { this["responseString"] = value; }
        }
    
        [ConfigurationProperty("matchWholeString")]
        public bool MatchWholeString
        {
            get
            {
                return (bool)this["matchWholeString"];
            }
            set
            {
                this["matchWholeString"] = value.ToString();
            }
        }
    
        [ConfigurationProperty("retryCount")]
        public int RetryCount
        {
            get
            {
                return (int)this["retryCount"];
            }
            set
            {
                this["retryCount"] = value.ToString();
            }
        }
    
        [ConfigurationProperty("failsProcess")]
        public bool FailsProcess
        {
            get
            {
                return (bool)this["failsProcess"];
            }
            set
            {
                this["failsProcess"] = value.ToString();
            }
        }
    
        public int TryCount
        {
            get { return this.m_tryCount; }
            set { this.m_tryCount = value; }
        }
    
        public void Reset()
        {
            this.m_tryCount = 0;
        }
    
    }
    

    This would then use xml like the following:

        <ServiceResponseList>
        <ServiceResponses>
            <clearServiceResponses/>
            <addServiceResponse responseString="API Server Login Error" matchWholeString="false" retryCount="5" failsProcess="false"/>
        </ServiceResponses>
    </ServiceResponseList>
    

    The main point is that I am using a collection (which you have in your example, actually a couple of them). Within that collection is an object that I am representing. So to get it to parse the xml you have you would have to make a section handler to match what you are using.

    Based on my example you would probably want to change your xml to something along the line of:

    <monitor>
      <screens>
        <screen height="800" width="1280">
          <regions>
             <region startupApplication="Internet" width="426" height="266" x1="0" x2="0" y1="0" y2="0"/>
         </regions>
       </screen>
      </screens>
    </monitor>
    

    You could then use classes similar to my example. Although you could probably get what you are wanting but you will need to use other configuration items to get it to work that way.

    Hope that helps.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

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

Top Members

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.