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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:10:26+00:00 2026-06-14T17:10:26+00:00

I have a class which inherits from a collection, specifically List<> and I’ve listed

  • 0

I have a class which inherits from a collection, specifically List<> and I’ve listed the class below. The problem I’m encountering when I serialize the object to XML using DataContractSerializer is the additional fields I’ve added within the object are not getting serialized by the serializer.
Here is the class:


[CollectionDataContract(Name = "ServiceEvents", Namespace = "")]
public class ServiceEventList : List<ServiceEvent> 
{
  [DataMember]
  public long StaleDate { get; set; }

  [DataMember]
  public long ExpirationDate { get; set; }
}

When I serialize the object and write to disk, here is the output (notice both StaleDate and ExpirationDate are missing).


<ServiceEvents xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><ServiceEvent><Date>2012-06-26T22:23:24.120817Z</Date><Description>A Service Event</Description><Id>634763462041210040</Id><Notes></Notes><Odometer>42</Odometer></ServiceEvent></ServiceEvents>

Here is the code that serializes the object:

using (FileStream fs = new FileStream(path, FileMode.Create))
{
  //TODO: StaleDate is not serializing to disk
  //TODO: ExpirationDate is not serializing to disk
  DataContractSerializer ser = new DataContractSerializer(typeof(ServiceEventList));
  ser.WriteObject(fs, list);
}

My next thought is to remove the inheritance structure and just embed a List object into the class. I’d prefer to just extend List but won’t waste more time on it if the community confirms my approach won’t work. Thanks in advance for the advice.

  • 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-14T17:10:27+00:00Added an answer on June 14, 2026 at 5:10 pm

    According to this post:

    http://social.msdn.microsoft.com/Forums/eu/wcf/thread/57eb195a-43a9-47fe-8b1a-a9d23feb2df2

    the problem is indeed that you inherit from a collection type – in this case the DataContractSerializer serializes only its items, but not any extra properties.

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

Sidebar

Related Questions

I have a class with a custom list which inherits from List and cannot
I have a collection class which inherits from BindingList and I can use the
I have a custom list which inherits from Generic.List<T> like this: public class TransferFileList<T>
I have a class which inherits from Canvas. On the OnRender method I draw
I have my class X which inherits from Qt's class Base . I declared
I have a class B which inherits from A which in turn derives from
I have a class called ModelView which inherits from NSOpenGLView. When my program runs
I have a form builder class which inherits from AbstractType and I need to
I have copied class from net which inherits UIImageView. How to put that class
I have two classes (MVC view model) which inherits from one abstract base 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.