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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:16:55+00:00 2026-06-04T18:16:55+00:00

I’m using DataContracts to serialize objects. Suppose I have serialized a data structured in

  • 0

I’m using DataContracts to serialize objects. Suppose I have serialized a data structured in this way:

[DataContract]
public class Dog : IExtensibleDataObject
{
    [DataMember]
    public int age;

    [DataMember]
    public string name;

    ExtensionDataObject IExtensibleDataObject.ExtensionData { get; set; }
}

Now I’m changing my architecture and I would like to read the previously serialized data with this classes:

[DataContract]
[KnownType(typeof(Dog))]
public class Animal : IExtensibleDataObject
{
    [DataMember]
    public string name;

    ExtensionDataObject IExtensibleDataObject.ExtensionData { get; set; }
}

[DataContract]
public class Dog : Animal
{
    [DataMember]
    public int age;
}

but I obtain name = null. I know that this depends on the order: the file was saved with age for first and then read starting from name, because it is on the base class.
Is there a way to handle this, maybe by changing the order?

  • 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-04T18:16:57+00:00Added an answer on June 4, 2026 at 6:16 pm

    I don’t think that’s possible.

    The xml in the past would have been

    <dog>
        <name>Bob</name>
        <age>10</age>
    </dog>
    

    Its now expecting

    <animal>
        <name>Bob</name>
        <dog>
            <age>10</age>
        </dog>
    </animal>
    

    The property is higher up in anything that’s serialized on the new DataContract.
    Changing inheritance heirarchy is a breaking change with the IExtensibleDataObject method.

    The use of inheritance together with data contracts is allowed,
    provided that inheritance is not used as a versioning mechanism and
    that certain rules are followed. If a type derives from a certain base
    type, do not make it derive from a different base type in a future
    version (unless it has the same data contract). There is one exception
    to this: you can insert a type into the hierarchy between a data
    contract type and its base type, but only if it does not contain data
    members with the same names as other members in any possible versions
    of the other types in the hierarchy. In general, using data members
    with the same names at different levels of the same inheritance
    hierarchy can lead to serious versioning problems and should be
    avoided.

    More at Best Practices: Data Contract Versioning

    Edit 1:

    You could perhaps try making Name virtual in Animal and overriding it in Dog? Or some crazy method to force the serialized new version to have name under dog. i.e. something like,

    [DataContract] 
    [KnownType(typeof(Dog))] 
    public class Animal : IExtensibleDataObject 
    {
        public virtual string name; 
    
        ExtensionDataObject IExtensibleDataObject.ExtensionData { get; set; } 
    } 
    
    [DataContract] 
    public class Dog : Animal 
    { 
        [DataMember] 
        public override string name; 
    
        [DataMember] 
        public int age; 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.