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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:54:46+00:00 2026-06-13T18:54:46+00:00

I am trying to create custom section in app.config file <?xml version=1.0 encoding=utf-8 ?>

  • 0

I am trying to create custom section in app.config file

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="BlogSettings" type="ConsoleApplication1.BlogSettings,   
      ConsoleApplication1" />
  </configSections>
  <BlogSettings
    Price="10"
    title="BLACKswastik" />
</configuration> 

C# code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string title = BlogSettings.Settings.Title;

            Console.WriteLine(title);
            Console.ReadKey();
        }
    }

    public class BlogSettings : ConfigurationSection
    {
        private static BlogSettings settings
          = ConfigurationManager.GetSection("BlogSettings") as BlogSettings;

        public static BlogSettings Settings
        {
            get
            {
                return settings;
            }
        }

        [ConfigurationProperty("Price"
          , DefaultValue = 20
          , IsRequired = false)]
        [IntegerValidator(MinValue = 1
          , MaxValue = 100)]
        public int Price
        {
            get { return (int)this["Price"]; }
            set { this["Price"] = value; }
        }


        [ConfigurationProperty("title"
          , IsRequired = true)]
        [StringValidator(InvalidCharacters = "  ~!@#$%^&*()[]{}/;’\"|\\"
          , MinLength = 1
          , MaxLength = 256)]
        public string Title
        {
            get { return (string)this["title"]; }
            set { this["title"] = value; }
        }
    }
}

but when I run this code I am getting this error:

The type initializer for ‘ConsoleApplication1.BlogSettings’ threw an
exception.

Please suggest me whats wrong I am doing.

  • 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-13T18:54:47+00:00Added an answer on June 13, 2026 at 6:54 pm

    You should check out Jon Rista’s three-part series on .NET 2.0 configuration up on CodeProject.

    • Unraveling the mysteries of .NET 2.0 configuration
    • Decoding the mysteries of .NET 2.0 configuration
    • Cracking the mysteries of .NET 2.0 configuration

    Highly recommended, well written and extremely helpful! This will give you a thorough understanding of the .NET configuration system.

    Phil Haack also has a great blog post Three easy steps to a custom configuration section that will give you a quick head-start into building your own custom config sections.

    To design your own custom section, there’s also a handy tool (Visual Studio add-in) called Configuration Section Designer that will make it very easy and simple to create your own custom section and have it build up all the necessary code to handle that custom section.

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

Sidebar

Related Questions

Trying to create a custom configuration elements as seen below: <?xml version=1.0 encoding=utf-8 ?>
I am trying to create a custom config section to load the list of
Im trying to create a custom version of the RequiredAttribute to replace the built
I am trying to define custom settings in my web.config file and I'm pretty
I'm trying to create a custom TabItem that is dynamically added to a TabControl
I am trying to create a custom User library in CodeIgniter. Inside this library
I'm trying to create a custom SELECT query to find my Personal Best races
I'm trying to create a custom form input that utilizes some images, it should
I'm trying to create a custom component to extend PrimeFaces. I have a simple
I am trying to create a custom popup view that can be called from

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.