WCF & KnownType : Weird BehaviourDear All,<br/> I am new to WCF and I checked out the forum to find a solution but found nothing. <br/> BTW, I have a base class called BaseData which is defined as bellow:<br/> <br/>     [DataContract(Namespace = &quot;http://localhost/KnownType&quot;)]<br/>     [KnownType(typeof(SubData))]<br/>     public class BaseData<br/>     {<br/>         [DataMember]<br/>         public virtual int ID<br/>         {<br/>             get;<br/>             set;<br/>         }<br/>     }<br/> <br/> There is also a derived class called SubData:<br/> <br/>     [DataContract(Namespace = &quot;http://localhost/KnownType&quot;)]<br/>     public class SubData :BaseData<br/>     {<br/>         [DataMember]<br/>         public override int ID {get;set;}<br/>     }<br/> <br/> As you see SubData overrides ID property. Therefore, at client side, an instance of either BaseData or SubData must have a ID property. Bur surprisingly when I create a proxy using Visual Studio, I see that an instance of BaseData has an ID , but an instance of SubData doesn't. Why it is like that?? <br/> For your info I will bring the definition of the ServiceContract here:<br/> <br/> [ServiceContract]<br/>     public interface IKnownType<br/>     {<br/>         [OperationContract]<br/>         SubData GetData();<br/>     }<br/> <br/>     [ServiceBehavior(Namespace = &quot;http://localhost/KnownType&quot;)]<br/>     public class KnownType : IKnownType<br/>     {<br/>         public SubData GetData()<br/>         {<br/>             return new SubData() { ID = 10 };<br/>         }<br/>     }© 2009 Microsoft Corporation. All rights reserved.Thu, 09 Jul 2009 12:58:38 Z49034635-9263-4674-9c51-7917155204d1http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/49034635-9263-4674-9c51-7917155204d1#49034635-9263-4674-9c51-7917155204d1http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/49034635-9263-4674-9c51-7917155204d1#49034635-9263-4674-9c51-7917155204d1ArefKhttp://social.msdn.microsoft.com/Profile/en-US/?user=ArefKWCF & KnownType : Weird BehaviourDear All,<br/> I am new to WCF and I checked out the forum to find a solution but found nothing. <br/> BTW, I have a base class called BaseData which is defined as bellow:<br/> <br/>     [DataContract(Namespace = &quot;http://localhost/KnownType&quot;)]<br/>     [KnownType(typeof(SubData))]<br/>     public class BaseData<br/>     {<br/>         [DataMember]<br/>         public virtual int ID<br/>         {<br/>             get;<br/>             set;<br/>         }<br/>     }<br/> <br/> There is also a derived class called SubData:<br/> <br/>     [DataContract(Namespace = &quot;http://localhost/KnownType&quot;)]<br/>     public class SubData :BaseData<br/>     {<br/>         [DataMember]<br/>         public override int ID {get;set;}<br/>     }<br/> <br/> As you see SubData overrides ID property. Therefore, at client side, an instance of either BaseData or SubData must have a ID property. Bur surprisingly when I create a proxy using Visual Studio, I see that an instance of BaseData has an ID , but an instance of SubData doesn't. Why it is like that?? <br/> For your info I will bring the definition of the ServiceContract here:<br/> <br/> [ServiceContract]<br/>     public interface IKnownType<br/>     {<br/>         [OperationContract]<br/>         SubData GetData();<br/>     }<br/> <br/>     [ServiceBehavior(Namespace = &quot;http://localhost/KnownType&quot;)]<br/>     public class KnownType : IKnownType<br/>     {<br/>         public SubData GetData()<br/>         {<br/>             return new SubData() { ID = 10 };<br/>         }<br/>     }Thu, 02 Jul 2009 04:32:05 Z2009-07-02T04:32:05Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/49034635-9263-4674-9c51-7917155204d1#68e58b76-e4d4-4577-ab13-77938045a71ahttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/49034635-9263-4674-9c51-7917155204d1#68e58b76-e4d4-4577-ab13-77938045a71aManesh_Ghttp://social.msdn.microsoft.com/Profile/en-US/?user=Manesh_GWCF & KnownType : Weird Behaviour<p>While creating proxy it doesnot create implementation for inherited class properties .<br/><br/>Other way is u can add your service reference in your client application and can accees <br/>your ID property from both classes instances</p><hr class="sig">ManeshThu, 02 Jul 2009 07:22:43 Z2009-07-02T07:22:43Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/49034635-9263-4674-9c51-7917155204d1#50bad711-04ac-47a9-8ddb-f7ad7aea7a28http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/49034635-9263-4674-9c51-7917155204d1#50bad711-04ac-47a9-8ddb-f7ad7aea7a28ArefKhttp://social.msdn.microsoft.com/Profile/en-US/?user=ArefKWCF & KnownType : Weird BehaviourHi Manesh<br/> Thanks for the reply. May you please let me know what is the difference between creating a proxy and adding a WCF service reference?<br/> <br/> ThanksThu, 02 Jul 2009 12:58:35 Z2009-07-02T12:58:35Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/49034635-9263-4674-9c51-7917155204d1#b4363349-589b-4820-ad7e-61af7e3422b4http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/49034635-9263-4674-9c51-7917155204d1#b4363349-589b-4820-ad7e-61af7e3422b4Richard Blewetthttp://social.msdn.microsoft.com/Profile/en-US/?user=Richard%20BlewettWCF & KnownType : Weird BehaviourAdding a service reference generates the code for the proxy on the client side so they are basically the same thing (although creating a proxy could also mean instantiating an instance of the proxy class)<br/><br/>The contract defines what data is to be passed, it doesn;t define OO semantics for the classes contract. As far as the client is concerned it has a faithful representation of the data that the service exposes. A base class with an ID and a class that derives from it<hr class="sig">Richard Blewett, <a href="http://www.thinktecture.com">thinktecture</a> - <a href="http://www.dotnetconsult.co.uk/weblog2">http://www.dotnetconsult.co.uk/weblog2</a><br/> Twitter: <a href="http://twitter.com/richardblewett">richardblewett</a>Thu, 02 Jul 2009 13:30:01 Z2009-07-02T13:30:01Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/49034635-9263-4674-9c51-7917155204d1#9c792160-bb65-441c-8099-6a4022f8413fhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/49034635-9263-4674-9c51-7917155204d1#9c792160-bb65-441c-8099-6a4022f8413fDhananjay25http://social.msdn.microsoft.com/Profile/en-US/?user=Dhananjay25WCF & KnownType : Weird BehaviourHi AreFk,  <div><br/></div> <div><strong>See  There is no probelm in your code. It is working fine for me .  You just remove your service refernece and add it again at client.  For your better undersatding , I have pasted 4 different combinations for  your code and 3rd and 4th combination is working fine. </strong></div> <div><strong><br/></strong></div> <div><strong>So , there is no probelem in your code </strong></div> <div><strong><br/></strong></div> <div><strong>1. Just rebuild the service </strong></div> <div><strong>2. Host it again </strong></div> <div><strong>3. update serveice reference at cleint and you are done my dear friend <br/></strong> <div><br/></div> <div>I tried out three combinations to answer you . </div> <div>First is  I replaced <strong>[DataContract] </strong> of base class with <strong>Serilizable</strong> attribute. And I left service implentation as same of your implentation . </div> <div><br/></div> <div> <pre lang="x-c#"> [Serializable] public class BaseData { [DataMember] public int ID { get; set; } } [DataContract] public class SubData:BaseData { [DataMember] public int ID { get; set; } } } </pre>  Surprisngly at the client side ,  I  am getting two ID , ID1 ( I know , why I am getting two ID because , I am not overriding the ID field). But I am getting ID property exposed for the subclass .</div> <div><br/></div> <div> <pre lang="x-c#"> Service1Client proxy = new Service1Client(); SubData obj = new SubData(); obj.ID = 9; obj.ID1 = 10; Console.WriteLine(obj.ID); Console.WriteLine(obj.ID1); Console.ReadKey(true);</pre> Second , when I changed the class like below </div> <div> <pre lang="x-c#">[Serializable] public class BaseData { [DataMember] public virtual int ID { get; set; } } [DataContract] public class SubData:BaseData { [DataMember] public override int ID { get; set; } }</pre> <br/></div> <div><br/></div> <div>I am not getting <strong>ID</strong> for either of the class.  where aas I am getting <strong>Idk_backingField. </strong>I am not sure whether, it is substitution of ID property  ?</div> <div><strong><br/></strong></div> <div><strong> <pre lang="x-c#"> Service1Client proxy = new Service1Client(); SubData obj = new SubData(); BaseData baseobj = new BaseData(); baseobj.IDk__BackingField = 10; obj.IDk__BackingField = 10; Console.WriteLine(obj.IDk__BackingField); Console.WriteLine(baseobj.IDk__BackingField); Console.ReadKey(true); </pre> 3rd try which is youe solution </strong></div> <div><strong><br/></strong></div> <div>I changed classes as</div> <div><br/></div> <div> <pre lang="x-c#"> [DataContract] public class BaseData { [DataMember] public virtual int ID { get; set; } } [DataContract] public class SubData:BaseData { [DataMember] public override int ID { get; set; } }</pre>  and at the client side , I am getting <strong>ID</strong> property exposed for both of the classes . see the client code below. </div> <div><br/></div> <div> <pre lang="x-c#"> Service1Client proxy = new Service1Client(); SubData obj = new SubData(); BaseData baseobj = new BaseData(); obj.ID = 9; baseobj.ID = 10; Console.WriteLine(obj.ID); Console.WriteLine(baseobj.ID ); Console.ReadKey(true);</pre> <br/></div> <div>So Id for both of the classes are exposed. </div> <div><br/></div> <div>Now coming to  <strong>your class definition </strong></div> <div><br/></div> <div> <pre lang="x-c#"> [DataContract(Namespace=&quot;http://localhost/KnownType&quot;)] [KnownType(typeof(SubData))] public class BaseData { [DataMember] public virtual int ID { get; set; } } [DataContract(Namespace = &quot;http://localhost/KnownType&quot;)] public class SubData:BaseData { [DataMember] public override int ID { get; set; } }</pre>  </div> <div>At client side both <strong>Id </strong>is exposed .</div> <div><br/></div> <div> <pre lang="x-c#"> Service1Client proxy = new Service1Client(); SubData obj = new SubData(); BaseData baseobj = new BaseData(); obj.ID = 9; baseobj.ID = 10; Console.WriteLine(obj.ID); Console.WriteLine(baseobj.ID ); Console.ReadKey(true); </pre> <br/></div> <div><br/></div> </div><hr class="sig">Thanks Dhananjay Kumar <br/> My Articles on <a>http://www.c-sharpcorner.com/Authors/AuthorDetails.aspx?AuthorID=dhananjaycoder </a> <br/> Contact me at dhananjay.25july@gmail.com Thu, 02 Jul 2009 14:18:09 Z2009-07-02T14:18:09Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/49034635-9263-4674-9c51-7917155204d1#2871414a-4527-4bf0-8dfa-a3ffed6d994fhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/49034635-9263-4674-9c51-7917155204d1#2871414a-4527-4bf0-8dfa-a3ffed6d994fArefKhttp://social.msdn.microsoft.com/Profile/en-US/?user=ArefKWCF & KnownType : Weird BehaviourHi <span class=fullbadge><a class=author rel=nofollow href="../../../../Profile/en-US/?user=Dhananjay25&amp;referrer=http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/49034635-9263-4674-9c51-7917155204d1?prof%3drequired&amp;rh=bnCcmPKJZaekqUgObSnrfN/PAkHpRQYh2KXNf0G5/eI%3d&amp;sp=forums" class=author><span class=name>Dhananjay25</span> </a> ,<br/> Thank you very much for the exhaustive answer. I wrote that code within Visual Studio 2010 Beta 1 , is it possible to be a bug of VS?<br/> I will check that code out in  VS 2008 and will be back to you :)<br/> <br/> Thanks<br/> Aref</span>Sat, 04 Jul 2009 04:04:53 Z2009-07-04T04:04:53Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/49034635-9263-4674-9c51-7917155204d1#15d6a4d9-0955-47f0-9496-f1add6954f5dhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/49034635-9263-4674-9c51-7917155204d1#15d6a4d9-0955-47f0-9496-f1add6954f5dArefKhttp://social.msdn.microsoft.com/Profile/en-US/?user=ArefKWCF & KnownType : Weird BehaviourYes, it seems to be a bug in VS2010. I checked that code with VS2008 and it works fine. <br/> <br/> Thank you allSat, 04 Jul 2009 04:31:45 Z2009-07-04T04:31:45Zhttp://social.msdn.microsoft.com/Forums/en-US/wcf/thread/49034635-9263-4674-9c51-7917155204d1#eb64f0b4-b77f-465e-aa1a-3428c3204bd2http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/49034635-9263-4674-9c51-7917155204d1#eb64f0b4-b77f-465e-aa1a-3428c3204bd2Dhananjay25http://social.msdn.microsoft.com/Profile/en-US/?user=Dhananjay25WCF & KnownType : Weird BehaviourHave u cheked with VS2010. R u getting the same behavior<hr class="sig">Thanks Dhananjay Kumar <br/> My Articles on <a>http://www.c-sharpcorner.com/Authors/AuthorDetails.aspx?AuthorID=dhananjaycoder </a> <br/> Contact me at dhananjay.25july@gmail.com Thu, 09 Jul 2009 12:58:38 Z2009-07-09T12:58:38Z