views:

281

answers:

1

My desktop application serializes objects using XmlSerializer. I was suggested to leverage DataContractSerializer instead.
Under which scenarios should I use DataContractSerializer?

Many thanks

Comments.
1. The output XML file is stored locally. No other applications deserialize objects from that XML file.
2. My application runs with .NET Framework 3.5 SP1.

+1  A: 

Dan Rigsby has the ultimate post on this - go read it!

XmlSerializer vs. DataContractSerializer

He says all there is to say, and it a very convincing way.

In short:

XmlSerializer is:

  • been around for a long time
  • is "opt-out"; everything public gets serialized, unless you tell it not to ([XmlIgnore])

DataContractSerializer is:

  • new kid in town
  • optimized for speed (about 10% faster than XmlSerializer, typically)
  • in "opt-in" - only stuff you specifically mark as [DataMember] will be serialized
  • doesn't support XML attributes (for speed reasons)
marc_s