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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:46:08+00:00 2026-06-01T11:46:08+00:00

Possible Duplicate: How to serialize an IList<T>? I wish to serialize an class (let’s

  • 0

Possible Duplicate:
How to serialize an IList<T>?

I wish to serialize an class (let’s call it S) that contains a property of the type IList<T> where T is another class which I have defined. I get an exception when I attempted to serialize an instance of class S to XML. This is understandable as the XmlSerializer doesn’t know which concrete class to use. Is there a way, hopefully using attributes, to specify which concrete class to instantiate when serializing/deserializing an instance. My implementation of class S creates a instance of the List<T> class. Here is some code to illustrate my example:

using System;
using System.Xml.Serialization;
using System.IO;

[Serializable]
public class T { }

[Serializable]
public class S
{
    public IList<T> ListOfTs { get; set; }

    public S()
    {
        ListOfTs = new List<T>();
    }
}

public class Program
{
    public void Main()
    {
        S s = new S();
        s.ListOfTs.Add(new T());
        s.ListOfTs.Add(new T());
        XmlSerializer serializer = new XmlSerializer(typeof(S));
        serializer.Serialize(new StringWriter(), s);
    }
}

I’m hoping there’s an attribute I can place above the ListOfTs definition that says to the serialize, “assume an instance of List<T> when serializing/deserializing”.

  • 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-01T11:46:10+00:00Added an answer on June 1, 2026 at 11:46 am

    Change the

    public IList<T> ListOfTs { get; set; }
    

    to

    public List<T> ListOfTs { get; set; }
    

    Then it will work.

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

Sidebar

Related Questions

possible duplicate: Cannot serialize parameter of type ‘System.Linq.Enumerable… ’ when using WCF, LINQ, JSON
Possible Duplicate: Yield In VB.NET In C#, when writing a function that returns an
Possible Duplicate: How do I serialize an enum value as an int? Hi, all!
Possible Duplicate: How to (xml) serialize a uri To my knowledge Uri implements ISerializable,
Possible Duplicate: NAnt or MSBuild, which one to choose and when? What is the
Possible Duplicate: Serializing to JSON in jQuery I know how to serialize an object
Possible Duplicate: Python urllib2 Progress Hook I have a script which uploads a file
Possible Duplicate: Cache Object in PHP without using serialize So I have built a
Possible Duplicate: How to serialize in c++? How to implement serialization in C++ I've
Possible Duplicate: Serializable Inheritance Is serialization inheritable? Example: [Serializable] class A { } class

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.