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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:18:34+00:00 2026-05-15T08:18:34+00:00

I want to implement Craig Andera’s custom XML configuration handler in a slightly different

  • 0

I want to implement Craig Andera’s custom XML configuration handler in a slightly different scenario. What I want to be able to do is to read in a list of arbitrary length of custom objects defined as:

public class TextFileInfo
{
    public string Name { get; set; }
    public string TextFilePath { get; set; }
    public string XmlFilePath { get; set; }
}

I managed to replicate Craig’s solution for one custom object but what if I want several?

Craig’s deserialization code is:

public class XmlSerializerSectionHandler : IConfigurationSectionHandler
{
    public object Create(object parent, object configContext, XmlNode section)
    {
        XPathNavigator nav = section.CreateNavigator();
        string typename = (string)nav.Evaluate("string(@type)");
        Type t = Type.GetType(typename);
        XmlSerializer ser = new XmlSerializer(t);
        return ser.Deserialize(new XmlNodeReader(section));
    }
}

I think I could do this if I could get

Type t = Type.GetType("System.Collections.Generic.List<TextFileInfo>")

to work but it throws

Could not load type 'System.Collections.Generic.List<Test1.TextFileInfo>' from assembly 'Test1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
  • 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-15T08:18:35+00:00Added an answer on May 15, 2026 at 8:18 am

    I don’t think this would work in that scenario. Craig’s solution works well for simple object graphs, but collections are a little trickier. Lists are serialised as arrays, so putting your example in, a serialised List is something like:

    <ArrayOfTextFileInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlsns:xsd="http://www.w3.org/2001/XMLSchema>
      <TextFileInfo>
        <Name>My Text File</Name>
        <TextFilePath>C:\MyTextFile.txt</TextFilePath>
        <XmlFilePath>C:\MyXmlFile.xml</XmlFilePath>
      </TextFileInfo>
    </ArrayOfTextFileInfo>
    

    Now, I’m guessing you could probably put that in a config, as long as the config section is named as “ArrayOfTextFileInfo”. Not exactly that friendly. I think what you should probably do is use the standard configuration classes to build this:

    public class TextFileConfigurationElement : ConfigurationElement
    {
      [ConfigurationProperty("name", IsRequired = true, IsKey = true)]
      public string Name { 
        get { return (string)this["name"]; }
        set { this["name"] = value; }
      }
    
      [ConfigurationProperty("textFilePath")]
      public string TextFilePath {
        get { return (string)this["textFilePath"]; }
        set { this["textFilePath"] = value; }
      }
    
      [ConfigurationProperty("xmlFilePath")]
      public string XmlFilePath {
        get { return (string)this["xmlFilePath"]; }
        set { this["xmlFilePath"] = value; }
      }
    }
    
    [ConfigurationCollection(typeof(TextFileConfigurationElement))]
    public class TextFileConfigurationElementCollection : ConfigurationElementCollection
    {
      protected override void CreateNewElement() {
        return new TextFileConfigurationElement();
      }
    
      protected override object GetElementKey(ConfigurationElement element) {
        return ((TextFileConfigurationElement)element).Name;
      }
    }
    
    public class TextFilesConfigurationSection : ConfigurationSection
    {
      [ConfigurationProperty("files")]
      public TextFileConfigurationElementCollection Files {
        get { return (TextFileConfigurationElementCollection)this["files"]; }
        set { this["files"] = value; }
      }
    
      public static TextFilesConfigurationSection GetInstance() {
        return ConfigurationManager.GetSection("textFiles") as TextFilesConfigurationSection;
      }
    }
    

    Once you’ve registered the config section:

    <configSections>
      <add name="textFiles" type="...{type here}..." />
    </configSections>
    

    You can add in the configs:

    <textFiles>
      <files>
        <add name="File01" textFilePath="C:\File01.txt" xmlTextFile="C:\File01.xml" />
      </files>
    </textFiles>
    

    Using that in code:

    public List<TextFileInfo> GetFiles() {
      var list = new List<TextFileInfo>();
    
      var config = TextFileConfigurationSection.GetInstance();
      if (config == null)
        return list;
    
      foreach (TextFileConfigurationElement fileConfig in config.Files) {
        list.Add(new TextFileInfo 
                            {
                              Name = fileConfig.Name,
                              TextFilePath = fileConfig.TextFilePath,
                              XmlFilePath = fileConfig.XmlFilePath
                             });
    
      }
    
      return list;
    }
    

    Also, this:

    Type t = Type.GetType("System.Collections.Generic.List<TextFileInfo>")
    

    Won’t work for a couple of reasons, you haven’t fully qualified the TextFileInfo type (needs a namespace), and your definition of a generic type is wrong (I can see why you haven’t specified it that way), it should look like:

    Type t = Type.GetType("System.Collections.Generic.List`1[MyNamespace.TextFileInfo]");
    

    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 497k
  • Answers 497k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer As long as you pass the session id cookie, you… May 16, 2026 at 12:00 pm
  • Editorial Team
    Editorial Team added an answer Ranges can only be integer ordinal types. You will need… May 16, 2026 at 12:00 pm
  • Editorial Team
    Editorial Team added an answer Based on my understanding, in CSS the background image starts… May 16, 2026 at 12:00 pm

Trending Tags

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

Top Members

Related Questions

I Want Implement a Software by C#.net.I want Use a DataBase Manager Software like
I want implement in my software solution an VBA editor but in c# 3.0.
I want implement paging same as safari in iphone.When user touch below button of
i have question for example i want to implement binary tree with array i
given this class definition: public class Frame { IFrameStream CapturedFrom; } I want implement
Microsoft has announce that WindowsLiveID become a OpenID provider . I want implement it
I want to implement this function: Public Function GetFunc(Of TSource, TResult) _ selector As
I want to implement the floating window in the html which it has scroll
Hi i want to implement a copy feature so that i can right click
I am working on a django project, where I want to implement a signal

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.