DataContractSerializer vs. NetDataContractSerializer

While browsing through the bowels of MSDN I ran across this page that describes the NetDataContractSerializer.  I’ve never really thought much about it but it is useful to learn something new so I ran the sample code which serializes a person object to an XML file.

Then I changed the code to serialize using the DataContractSerializer.

According to MSDN the big difference between the two is that the NetDataContractSerializer passes type information in the XML which allows you to create a tighter .NET to .NET implementation (if that is what you want).

Here is the DataContractSerializer version of the Person data

<Customer xmlns="" xmlns:i="">

And here is the version from the NetDataContractSerializer

<Customer z:Id="1" z:Type="NetDCS.Person" z:Assembly="NetDCS, Version=, Culture=neutral, PublicKeyToken=null" xmlns="" xmlns:i="" xmlns:z="">
  <FirstName z:Id="2">Zighetti</FirstName>
  <LastName z:Id="3">Barbara</LastName>

As you can see the NetDataContractSerializer included information about the type and the assembly which can be used on the client side.

So what does this mean to you?  Probably not much.  The WCF team viewed the NetDataContractSerializer as a compromise of tight coupling since it shares types between server and client.  Therefore they made it very difficult to use – Aaron Skonnard wrote a post a few years back that explains the details.  Tim Scott wrote an interesting post about how this helped to solve a problem in NHibernate as well – you might find these interesting…


By the way… I just have to say thanks to the MSDN team for finally coming up with a good UI solution for multiple language examples.  I like the current solution way better than anything else they had in the past – great job!

Skip to main content