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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T13:34:50+00:00 2026-06-18T13:34:50+00:00

I need to create a simple customized ConfigurationSection with an IEnumerable inside it. I

  • 0

I need to create a simple customized ConfigurationSection with an IEnumerable inside it.

I have read several articles and stackoverflow links, taking this as a simple example:
How to create custom config section in app.config?

So, I have this config file section inside a Console App:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="Disk"
             type="ConsoleApplication1_ConfigurationEnumerable.PathsConfigSection"/>
  </configSections>
  <Disk>
    <Paths>
      <Path name="one" permission="1" />
      <Path name="two" permission="2" />
      <Path name="three" permission="3" />
    </Paths>
  </Disk>
</configuration>

Next I have this whole structure to manage the config section:
using System.Configuration;

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

        [ConfigurationProperty("permission", IsRequired=true)]
        public string Permission
        {
            get
            {
                return (string)this["permission"];
            }
        }
    }    

    public class Paths: ConfigurationElementCollection 
    {
        public Path this[int index] 
        {
            get
            {
                return base.BaseGet(index) as Path;
            }
            set 
            {
                if (base.BaseGet(index) != null) {
                    base.BaseRemoveAt(index);
                }
                this.BaseAdd(index, value);
            }
        }

        protected override ConfigurationElement CreateNewElement() 
        {
            return new Path();
        }
        protected override object  GetElementKey(ConfigurationElement element)
        {
            return ((Path)element).Name;
        }
    }

    public class PathsConfigSection : ConfigurationSection
    {
        public static PathsConfigSection GetConfig()
        {
            //return (PathsConfigSection)System.Configuration.ConfigurationManager.GetSection("Disk") ?? new PathsConfigSection();
            return (PathsConfigSection)System.Configuration.ConfigurationManager.GetSection("Paths") ?? new PathsConfigSection();
        }

        [ConfigurationProperty("Paths")]
        public Paths Paths
        {
            get 
            {
                object o = this["Paths"];
                return o as Paths;
            }
        }
    }
}

And here the program.cs using the whole thing:
using System;

namespace ConsoleApplication1_ConfigurationEnumerable
{
    class Program
    {
        static void Main(string[] args)
        {
            var config = PathsConfigSection.GetConfig();
            if (config == null || config.Paths.Count == 0)
            {
                Console.WriteLine("Is null or empty");
            }
            else
            {
                foreach (Path item in config.Paths)
                {
                    Console.WriteLine("Item {0} with valuer {1}", item.Name, item.Permission);
                }
            }
        }
    }
}

The problem here is inside this two lines:

//return (PathsConfigSection)System.Configuration
//       .ConfigurationManager.GetSection("Disk") ?? new PathsConfigSection();
return (PathsConfigSection)System.Configuration
       .ConfigurationManager.GetSection("Paths") ?? new PathsConfigSection();

If I use the second one (uncommented above) it returns null.

If I use the commented one, then it throws an exception like this:

System.Configuration.ConfigurationErrorsException was unhandled
HResult=-2146232062 Message=An error occurred creating the
configuration section handler for Disk: Could not load type
‘ConsoleApplication1_ConfigurationEnumerable.PathsConfigSection’ from
assembly ‘System.Configuration, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a’.
(C:\Users\blackberry\Desktop\ConsoleApplication1_ConfigurationEnumerable\ConsoleApplication1_ConfigurationEnumerable\bin\Debug\ConsoleApplication1_ConfigurationEnumerable.vshost.exe.config
line 4) Source=System.Configuration BareMessage=An error occurred
creating the configuration section handler for Disk: Could not load
type ‘ConsoleApplication1_ConfigurationEnumerable.PathsConfigSection’
from assembly ‘System.Configuration, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a’.
Filename=C:\Users\blackberry\Desktop\ConsoleApplication1_ConfigurationEnumerable\ConsoleApplication1_ConfigurationEnumerable\bin\Debug\ConsoleApplication1_ConfigurationEnumerable.vshost.exe.config
Line=4 StackTrace:
at System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String
configKey, Boolean& isRootDeclaredHere)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String
configKey, Boolean getLkg, Boolean checkPermission, Boolean
getRuntimeObject, Boolean requestIsHere, Object& result, Object&
resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSection(String
configKey)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String
sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at ConsoleApplication1_ConfigurationEnumerable.PathsConfigSection.GetConfig()
in
C:\Users\blackberry\Desktop\ConsoleApplication1_ConfigurationEnumerable\ConsoleApplication1_ConfigurationEnumerable\Disk.cs:line
63
at ConsoleApplication1_ConfigurationEnumerable.Program.Main(String[]
args) in
C:\Users\blackberry\Desktop\ConsoleApplication1_ConfigurationEnumerable\ConsoleApplication1_ConfigurationEnumerable\Program.cs:line
9
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext
executionContext, ContextCallback callback, Object state, Boolean
preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean
preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart() InnerException: System.TypeLoadException
HResult=-2146233054
Message=Could not load type ‘ConsoleApplication1_ConfigurationEnumerable.PathsConfigSection’ from
assembly ‘System.Configuration, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a’.
Source=System.Configuration
TypeName=ConsoleApplication1_ConfigurationEnumerable.PathsConfigSection
StackTrace:
at System.Configuration.TypeUtil.GetTypeWithReflectionPermission(IInternalConfigHost
host, String typeString, Boolean throwOnError)
at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.Init(RuntimeConfigurationRecord
configRecord, FactoryRecord factoryRecord)
at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.InitWithRestrictedPermissions(RuntimeConfigurationRecord
configRecord, FactoryRecord factoryRecord)
at System.Configuration.RuntimeConfigurationRecord.CreateSectionFactory(FactoryRecord
factoryRecord)
at System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String
configKey, Boolean& isRootDeclaredHere)
InnerException:

Where is my fault ?

  • 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-06-18T13:34:51+00:00Added an answer on June 18, 2026 at 1:34 pm

    You need to use the Fully Qualified Assembly Name when specifying the class in the configSections tag:

    <configSections>
      <section name="Disk"
               type="ConsoleApplication1_ConfigurationEnumerable.PathsConfigSection, ConsoleApplication1"/>
    </configSections>
    

    This assumes that the name of your assembly is ConsoleApplication1. If you are still getting exceptions, you can determine the correct value using the the following code:

    typeof(ConsoleApplication1_ConfigurationEnumerable.PathsConfigSection).FullName
                                                                          .ToString()
    

    BTW: Your namespace is odd. Naming standard suggest that you use the dot (.) when separating namespace hierarchies:

    namespace ConsoleApplication1.ConfigurationEnumerable
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create some simple effects for the layers which I have created
With this code we can create a simple word document but I need to
I need to create simple reusable javascript object publishing several methods and parameterized constructor.
I need to create a simple application that would generate reports based on database
I need to create a simple drawing program in c for graphs, i.e. nodes
I need to create a simple Chat system like facebook chat and a twitter-like
I need to create a simple mySQL database with a field for an image.
For the purpose of the question I need to create a simple fictitious scenario.
Sometimes you need to create a very simple single file application in Qt4. However
How to create simple PHP COMET server page displaying current time? I need code

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.