DataContractAttribute with Shared Assembly

Posted by Sanju on Stack Overflow See other posts from Stack Overflow or by Sanju
Published on 2010-05-29T06:17:52Z Indexed on 2010/05/29 6:22 UTC
Read the original article Hit count: 194

Filed under:
|
|
|

Hi All,

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 assemblie) I can happily recieve 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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about wcf