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

  • Home
  • SEARCH
  • 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 828527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:44:19+00:00 2026-05-15T03:44:19+00:00

Is it necessary to decorate custom objects with [DataContract] and [DataMember] when using shared

  • 0

Is it necessary to decorate custom objects with [DataContract] and [DataMember] when using shared assemblies (as opposed to auto proxy generation)?

The reason I ask is that I have encountered the following scenario:

Suppose the following object is implemented in my service:

public class baseClass
{
  Guid _guid;

  public baseClass()
  {
      _guid = Guid.NewGuid()
  }

  public Guid ReturnGuid { get {return _guid;}}
}

public class newClass : baseClass
{
    int _someValue;

    public newClass {}

    public int SomeValue
    {
       get {return _someValue;}
       set {_someValue = value;}
    }
}

[ServiceContract]
public IService
{
   [OperationContract]
   newClass SomeOperation();
}

In my client (with shared assemblies) I can happily receive and use a serialized newClass when SomeOperation is called – even though I have not marked it as a DataContract.

However, as soon as I do mark it with DataContract and use DataMember then it complains that set is not implemented on ReturnGuid in the base class.

Could somebody explain why it works fine when I do not decorate with DataContract and DataMember.

Many thanks.

  • 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-15T03:44:19+00:00Added an answer on May 15, 2026 at 3:44 am

    Microsoft introduced a change in the .NET 3.5 Service Pack 1 in that the DataContract/DataMember attributes aren’t required anymore.

    So if you don’t want to, you don’t need to have those attributes. If you omit those attributes, the DataContractSerializer will serialize the object class just like the XmlSerializer would:

    • serializes all public read/write properties (properties which have both a get as well as a set method)
    • serializes them in the order they appear in the class definition

    So no – you don’t have to have those attributes anymore. But if you leave them out, you also loose the benefits of having them around: you cannot define a member to be required, you cannot define the order in which the attributes should be ordered in the serialized XML etc.

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

Sidebar

Ask A Question

Stats

  • Questions 448k
  • Answers 448k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you want to find out what's making it slow,… May 15, 2026 at 7:48 pm
  • Editorial Team
    Editorial Team added an answer I'm quite interested in this, too. I've flirted with HTML5's… May 15, 2026 at 7:48 pm
  • Editorial Team
    Editorial Team added an answer You can use the EXEC approach. declare @x nvarchar(2000) set… May 15, 2026 at 7:48 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.