New additions in 3.5 Sp1

In .NET 3.5 SP1 the following features are added to the DataContractSerializer. 1. Support for POCO types. Aaron has a nice writeup here. I have updated my post on Serialization Rules to include this. 2. Support for get-only collection properties. 3. Support for schema-verifiable multiple object reference (i.e using the same instance of an object…

3

All About KnownTypes

<This turned out to be longer than what I had intended. Sorry about it>   One of the common errors in Deserialization is “Element ”http://mycompany.com/:shape” contains data of the ‘http://mycompany.com/:Circle’ data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to ‘Circle’ to the list of…

18

Why prevent DataContract + IXmlSerializable

I left one thing unsaid in the serialization rules and Aaron’s sharp eyes caught it promptly. As he mentioned in his blog, mixing interface programming model (such as IXmlSerializable or ISerializable) with DataContract programming model is disallowed in V1.  Here is an example of such a class.   [DataContract] public class XmlDataContractType : IXmlSerializable {     [DataMember]     public…

4

Preserving Object Reference in WCF

By default object references are not preserved by the DataContractSerializer; Values of an object referenced multiple times is serialized multiple times. If the object is part of mutual (cyclic) reference (e.g. circular linked list) an exception is thrown during serialization.   DataContractSerializer can be made to preserve object reference by passing true for parameter PreserveObjectReference…

22

WCF Serialization Programming Model

DataContract is the default serialization programming model for WCF. However WCF supports more than just the types marked wth DataContract attribute. It supports serialization of the following kinds of types in the default mode. CLR built-in types Byte array, DateTime, TimeSpan, GUID, Uri, XmlQualifiedName, XmlElement and XmlNode array [This includes XElement and XNode array from…

21