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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:08:00+00:00 2026-05-31T22:08:00+00:00

I have a super class and two subclasses and I want to serialize the

  • 0

I have a super class and two subclasses and I want to serialize the objects of the subclasses as a list and deserialize it

I tried to use a super class list which had objects from both subclasses but ended up in an exception.

Is there any way to do it?

Type1 t = new Type1() { text="123" ,opt1=true,opt2=true};
Type2 t1 = new Type2() { text="1234",isAnswer=false};
Question q1 = new Question() { text="12321"};
Question q2 = new Question() { text = "12321" };
List<Question> q = new List<Question>() { t1 };
FileStream fs = new FileStream("aa.xml", FileMode.OpenOrCreate, FileAccess.Write);
XmlSerializer xs = new XmlSerializer(typeof(List<Question>));
//Exception is generated here InvalidOperationException
//there was error genearating the XML document
xs.Serialize(fs, q);

fs.Close();
  • 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-31T22:08:01+00:00Added an answer on May 31, 2026 at 10:08 pm

    Try passing the types to be known to the serializer, such as,

    serializer = new XmlSerializer(typeof(T), extraTypes); where extraTypes is an array of types that you have to be serialized.

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

Sidebar

Related Questions

I have a super-class named ClassA and two sub-classes Class1 and Class2. I have
Say I had a class SuperClass and two subclasses SubClassA and SubClassB that inherit
I have two classes like the following: class Super(object): def __init__(self, arg): self.arg =
If I have a superclass, say Animal , and two subclasses: Zebra and Giraffe
Let's say I have a table that represents a super class, students . And
If subclass in objective-c wants to override a super class's method, does it have
I have some classes which extends a superclass, and in the JSP I want
I have this object which is an instance of a superclass. I want to
I have two classes, one of which is a subclass of another, and differs
I have constructed a map and try to put subclasses of a given 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.