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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:25:20+00:00 2026-05-23T09:25:20+00:00

I Have a custom section in Web.Config file and referring another .config file through

  • 0

I Have a custom section in Web.Config file and referring another .config file through configSource. I have generated .cs file using the XSD for my schema. How to use my generated classes to deserialize the config. When I try to load the configsection using .GetSection() method, it gives me error that the class should implement from ConfigurationSection. Since I have generated the classes using xsd, they were not inherited from ConfigurationSection or ConfigurationElement. Thanks in advance!!

  • 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-23T09:25:20+00:00Added an answer on May 23, 2026 at 9:25 am

    I have implemented the class from ConfigurationSection to get the file name and using XMLSerializer to Deserialize using the classes generated by XSD tool. Here is sample:

    namespace mycontrol
    {
          public class ConfigurationSection : System.Configuration.ConfigurationSection
            {
               //Configuration is the type generated by XSD for my schema element Configuration
    
                private static Configuration _config; 
    
                /// <summary>
                /// static method to load config section and deserialize config
                /// </summary>
                /// <returns></returns>
                private static Configuration GetConfig()
                {
                    if (_config == null)
                    {
                        ConfigurationSection configSection = (ConfigurationSection)ConfigurationManager.GetSection("SearchControlsConfig") as ConfigurationSection;
                        if (!string.IsNullOrEmpty(configSection.ExternalConfigSource))
                        {
                            string strFilePath = configSection.ExternalConfigSource;
                            if (!File.Exists(strFilePath))
                            {
                                strFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strFilePath);
                                if (!File.Exists(strFilePath))
                                    return null;
                            }
    
                            using (FileStream fs = new FileStream(strFilePath, FileMode.Open, FileAccess.Read))
                            {
                                XmlSerializer config = new XmlSerializer(typeof(Configuration));
                                _config = (Configuration)config.Deserialize(fs);
                            }
                        }
    
                    }
    
                    return _config;
                }
    
    
                /// <summary>
                /// Attribute to specify config source file in custom config section
                /// </summary>
                [ConfigurationProperty("externalConfigSource", DefaultValue = "", IsRequired = false)]
                public string ExternalConfigSource
                {
                    get
                    {
                        return this["externalConfigSource"] as string;
                    }
                }
            }
    }
    

    I cannot use the configSource attribute as my property while specifying the custom config, because it is reserved by ConfigurationManager.

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

Sidebar

Related Questions

I have custom configuration section within web.config file. I'm lingering between: Reading it into
We have a custom section in my app.config file related to our IoC container
I have a custom configuration section registered in the app/web.config, let's call it MySection
I've create a custom configuration section in my web.config file for my 3.5 web
I have custom errors configured in my web.config, but IIS 6.0 is returning the
I have just rolled a custom configuration section, created an accompanying schema document for
I have a MyProject.config file that contains ConnectionStrings, AppSettings, and custom sections. I don't
I have a web application with a custom configuration section. That section contains information
I have a custom dll (CustomSoapExtension.dll) that I use in another webservice client (a
I'm using ASP.NET and rely on the web.config file to secure sections of my

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.