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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:53:06+00:00 2026-05-26T23:53:06+00:00

I am writing code that read customized config section from app.config, but I get

  • 0

I am writing code that read customized config section from app.config, but I get some errors, hope anyone can help to fig out.

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="Psptune" 
             type="ConfigurationSettings.PsptuneSection, ConfigurationSettings"/>
  </configSections>
  <Psptune>
    <psp>
      <FolderLocataions>
        <add name="PspFolder" directory="aa"/>
        <add name="IsoFolder" directory="aa"/>
      </FolderLocataions>
    </psp>
  </Psptune>
  <startup>
    <supportedRuntime version="v4.0" 
                      sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>


using System;

namespace ConfigurationSettings
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                var sec = PsptuneSection.Settings;
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
            Console.ReadKey();
        }
    }
}
using System.Configuration;

namespace ConfigurationSettings
{
    public class FolderLocationElement : ConfigurationElement
    {
        [ConfigurationProperty( "name", DefaultValue = "default", IsRequired = false)]
        [StringValidator(MinLength = 5, MaxLength = 256)]
        public string Name
        {
            get { return (string) this["name"]; }
            set { this["name"] = value;  }
        }

        [ConfigurationProperty("directory", DefaultValue = "default", IsRequired = false)]
        [StringValidator(MinLength = 5, MaxLength = 256)]
        public string Directory
        {
            get { return (string)this["directory"]; }
            set { this["directory"] = value; }
        }

    }
}

using System.Configuration;

namespace ConfigurationSettings
{
    public class FolderLocationElementCollection : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new FolderLocationElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((FolderLocationElement) element).Name;
        }

        public FolderLocationElement this[int index]
        {
            get { return (FolderLocationElement) BaseGet(index); }
        }

        public void Add(FolderLocationElement element)
        {
            BaseAdd(element);
        }
    }
}

using System.Configuration;

namespace ConfigurationSettings
{
    public class PspElement : ConfigurationElement
    {
        [ConfigurationProperty("FolderLocataions", DefaultValue = "default", IsRequired = false)]
        [StringValidator(MinLength = 5, MaxLength = 256)]
        public FolderLocationElementCollection FolderLocataions
        {
            get { return (FolderLocationElementCollection) this["FolderLocataions"]; }
            set { this["FolderLocataions"] = value; }
        }
    }
}

using System.Configuration;

namespace ConfigurationSettings
{
    public class PsptuneSection : ConfigurationSection
    {
        private static PsptuneSection _settings =
            ConfigurationManager.GetSection("Psptune") as PsptuneSection;

        public static PsptuneSection Settings { get { return _settings;  } }

        [ConfigurationProperty("psp", DefaultValue = "default", IsRequired = false)]
        public PspElement Psp
        {
            get { return (PspElement) this["psp"]; }
            set { this["psp"] = value; }
        }
    }
}

The exeception I get is:

System.TypeInitializationException: The type initializer for 'ConfigurationSetti
ngs.PsptuneSection' threw an exception. ---> System.Configuration.ConfigurationE
rrorsException: The default value of the property 'psp' cannot be parsed. The er
ror is: Object reference not set to an instance of an object.

  • 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-26T23:53:07+00:00Added an answer on May 26, 2026 at 11:53 pm

    Nevermind my friends i got it figure out, and you ppl can stop to vote me down. The problem is some of the element can not have default value

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

Sidebar

Related Questions

I am writing code that will use AJAX requests to get some HTML code
I am writing some code that downloads a file from a network resource to
I'm using c#. In many cases I'm writing code that can benefit from a
I'm writing some code that id like to be able to work with any
I'm writing some code that calls a web service, reads back the response and
I'm writing a program for an exercise that will read data from a file
I'm writing some C++ code that will have to send data over TCP/IP. I
I'm writing some code that makes an AJAX request to our web server. Our
I'm writing some server code that talks to a client process via STDIN. I'm
A common mistake when writing code that reads text from a stream in Java

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.