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 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: In java how do I serialize a class that is not marked
possible duplicate: Cannot serialize parameter of type ‘System.Linq.Enumerable… ’ when using WCF, LINQ, JSON
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: How to (xml) serialize a uri To my knowledge Uri implements ISerializable,
Possible Duplicate: Difference Between Equals and == in which cases equals() works exactly like
Possible Duplicate: Transparent images with C# WinForms I am coding an app which will
Possible Duplicate: Serializing to JSON in jQuery I know how to serialize an object
Possible Duplicate: WAMP Stack PHP Fatal error: Class ‘SoapClient’ not found I downloaded a
Possible Duplicate: Post the checkboxes that are unchecked I've got a problem with serializing
Possible Duplicate: Why XML-Serializable class need a parameterless constructor I'm getting the run-time error

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.