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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:19:56+00:00 2026-05-13T14:19:56+00:00

I have a base class like the following: [Serializable] public class SerializableDomainObject<T> { public

  • 0

I have a base class like the following:

[Serializable]
public class SerializableDomainObject<T>
{
    public SerializableDomainObject()
    {
        ID = Guid.NewGuid();
    }

    [DataMember(Name="ID", Order = 0)]
    public Guid ID { get; private set; }

    public void Save()
    {
        // serialize
    }

    public void Load()
    {
        // deserialize
    }
}

I then have lots of derived classes from this, here is an example of one:

[DataContract(Name="MyDomainObject")]
public class MyDomainObject : SerializableDomainObject<MyDomainObject>
{
    public MyDomainObject()
    {
    }

    public MyDomainObject(string name)
    {
        Name = name;
    }

    [DataMember(Order = 1)]
    public string Name { get; private set; }
}

Once serialized here is the output:

<MyDomainObject xmlns="http://schemas.datacontract.org/2004/07/DomainObjects" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <_x003C_ID_x003E_k__BackingField>2b3c00f6-1b15-4a6b-bd6c-a1f447ea5a34</_x003C_ID_x003E_k__BackingField>
    <Name>AName</Name>
</MyDomainObject>

Why is the ID property not being serialized with the name I have provided in the DataMember attribute in the base class?

  • 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-13T14:19:56+00:00Added an answer on May 13, 2026 at 2:19 pm

    It is because you have declared that setter for the property as private – since it is private, the DataContractSerializer is serializing the backing field and using its name rather then the property.

    The DataContractSerializer will happily serialize any members that you ask it to but with respect to the semantics of the language. It is usually best to declare your data contracts simply and without a lot of visibility control like this because the message contract between a service and a client should be straightforward and easy to consume. Create open and unrestricted data contracts but lock down your operation contracts.

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

Sidebar

Related Questions

Say I have a couple of basic objects like so: [Serializable] public class Base
I have a base class that looks like the following: template<typename T> class Base
I have something like the following in the header class MsgBase { public: unsigned
I have a base class like this: class base(object): name = def __init__(self,name): self.user
I have a class like the following: public class DropDownControl<T, Key, Value> : BaseControl
I have a base class with the following (trimmed for brevity) declaration: public abstract
I have an abstract entity base class defined like this: public abstract class SessionItem
Let's say I have two classes like the following: Class A { public: ..
I have a base class looking like this: public class BaseController : Controller {
I have this Base class: abstract class Base { public int x { get

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.