Using the [ContractNamespace] attribute to customize the namespace for POCO types

In .NET 3.5 SP1, DataContractSerializer was enhanced to support POCO types that weren’t marked with any serialization attributes at all. You can find my previous post about serializing POCO types here. But in some cases, you may want to customize the XML namespace of your POCO types without necessarily having to fall back to the…


Serializing Plain Old CLR Object (POCO) types with DataContractSerializer

When version 3.0 of the .NET framework shipped, DataContractSerializer could only support a few categories of CLR types. Sowmy has a good list of these that you can find here. The recommended model was to use DataContractAttributes on classes and structs along with DataMemberAttributes on fields and properties to customize the serialization of types. I…


Optimizing Away Repeat XML Namespace Declarations with DataContractSerializer

For performance reasons, DataContractSerializer can’t always figure out what namespaces will be used in a serialized instance ahead of time. And so, you may sometimes end up having a certain XML namespace defined over and over again when it only has to be declared once. This can be particularly painful because XML namespaces tend to…


Comparing the Performance of .NET Serializers

The .NET framework comes with a variety of different serializers. Hopefully, my overview of these serializers will have provided some insight into the differences between them and the various advantages and disadvantages of using different serializers. But there are not only great differences in functionality between the serializers, but there are also vast differences in…


Customizing the XML for collections with XmlSerializer and DataContractSerializer

One of the most common requests I get about serialization is to explain how to get collections to serialize out one way or another to XML. Specifically, developers are interested in being able to manipulate the hierarchy level of the collection within their XML and the names of the various XML elements. In today’s post,…


Configuring Known Types Dynamically – Introducing the DataContractResolver

This post has been updated to account for the changes to the DataContractResolver in the Beta 2 release of .NET 4.0.    This will be my first of several posts about new features that are showing up in the Beta 1 release of .NET 4.0. Beta 1 was released just a few weeks ago and you can download…


Understanding Known Types

Probably the aspect of WCF serialization developers have the hardest time with is known types. In fact, many developers don’t even understand why DataContractSerializer needs known types. They get so used to the principles of object-oriented design that they forget that anything that can be done in object-oriented design can’t necessarily be serialized and deserialized correctly….