NetDataContractSerializer vs DataContractSerializer

We have an application with objects that we would like to store in the database.
We are currently using the NetDataContractSerializer , but we recently found out that, due to the .Net information associated with it, it creates huge files, which means a slow application, even for basic objects.
We plan to upgrade to the DataContractSerializer instead, and I was looking for a good comparison of the two, but could not find.

  • What is the difference in size between the objects created by the two?
  • Is there a big difference in performance?
  • Is any of them problematic when I have an object containing List<X> , where X inherited by several other objects, so that the list contains many different types at runtime? (I was told that DataContractSerializer attributes can be set to KnownTypes , but that means more dependencies in the code. Is there a way to make the DataContractSerializer know all that types in my solution?)

Thanks.

+7
source share
1 answer
  • NetDataContractSerializer (NetDCS) records type information for all objects, while DataContractSerializer (DCS) records only those that are needed (i.e. if you declare an element as type B and the actual value of the member when it is serialized to type D, where D is a derived type from B, so there is much less โ€œnoiseโ€ in a serialized DCS serialized type.
  • Not really, but you should try both with your script to see if it affects you.
  • You need to use known types in DCS, but you can use DataContractResolver if you don't want to work with known types. An example of such a resolver can be found on the Youssef Massaoui blog , and some more information about the resolver can be found on my WCF extensibility post at http://blogs.msdn.com/b/carlosfigueira/archive/2011/09/21/wcf- extensibility-data-contract-resolver.aspx .
+9
source

All Articles