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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:54:16+00:00 2026-05-11T20:54:16+00:00

I have create testing application that has 3 classes Car Radio SportCar : Car

  • 0

I have create testing application that has 3 classes

  • Car
  • Radio
  • SportCar : Car (has a Radio)

As the serialize process when I create instance of XmlSerializer object I use 2 object to testing

XmlSerializer xmlSerializer = new XmlSerializer(typeof(SportCar));

and

XmlSerializer xmlSerializer = new XmlSerializer(
    typeof(SportCar), 
    new Type[] { typeof(Car), typeof(Radio) }); 

The result of this 2 approach is identical, so I want to know what is the difference between these 2 constructor or critical point that need to use #2 constructor?

  • 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-11T20:54:16+00:00Added an answer on May 11, 2026 at 8:54 pm

    The big difference is when you need to tell XmlSerializer about sub classes – for example:

    XmlSerializer xmlSerializer = new XmlSerializer(typeof(Car),
         new Type[] { typeof(SportCar), typeof(Radio) });
    

    Here, without the extra info if wouldn’t have known (just from Car) about either SportCar or Radio – so if you give it a object that is actually a SportCar, it would fail:

    Car car = new SportCar {...};
    xmlSerializer.Serialize(destination, car);
    

    You can also do this by setting [XmlInclude(typeof(SportCar))] against the Car type definition:

    [XmlInclude(typeof(SportCar))]
    public class Car {...}
    

    This is easier, but is only possible if the Car type is in an assembly that knows about SportCar. But you often do know this, so XmlInclude is the preferred option.

    Additionally: there are some efficiency benefits of XmlInclude; behind the scenes the system uses dynamic type generation to make XmlSerializer efficient. For this reason, you should generally keep hold of (and re-use) the XmlSerializer instance you create; for example, by storing it in a static field. However, the system does this automatically for the default usage (new XmlSerializer(typeof(Car))) – i.e. no matter how many times you use this constructor, it only generates the dynamic code once. If you use the more complex constructor (new XmlSerializer(typeof(Car),new Type[] { typeof(SportCar), typeof(Radio) })) it will do the type generation each time.

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

Sidebar

Related Questions

I have to create an application for testing that is relatively simple. If a
I'm currently looking into unit testing for a new application I have to create.
For testing purposes I need to create sets of text files that have similar
I have an application that I'm testing with rspec2 (2.6.4), capybara and selenium. When
I have a Delphi application that has many dependencies, and it would be difficult
I'm planning to distribute an application ad hoc for beta testing. I have created
I have several web services I need to create for them some testing mechanism
I have create my own NSOpenGLView class, right now the data that i want
i have create a form (so it's PHP and HTML hybrid-code). it has ability
I have an ASP.NET MVC web application that implements a custom membership provider. The

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.