Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scenarios where Xml Serialization fail in .NET

I would like to know the most common scenarios where xml serialization may fail in .NET.

like image 594
blitzkriegz Avatar asked Apr 08 '09 09:04

blitzkriegz


2 Answers

I'm thinking mainly of XmlSerializer here:

  • it is limited to tree-like data; it can't handle full object graphs
  • it is limited to public members, on public classes
  • it can't really do much with object members
  • it has some weaknesses around generics
  • like many serializers, it won't touch instance properties on a collection (bad practice in the first place)
  • xml simply isn't always a good choice for large data (not least, for performance)
  • requires a public parameterless constructor

DataContractSerializer solves some of these, but has its own limitations:

  • it can't handle values in attributes
  • requires .NET 3.0 (so not much use in 2.0)
like image 130
Marc Gravell Avatar answered Sep 20 '22 00:09

Marc Gravell


Cannot easily serialize generic collections.

See another question: C# XML Serialization Gotchas

like image 33
eddiegroves Avatar answered Sep 18 '22 00:09

eddiegroves