XML Serialization

  • Thread starter Thread starter Anuj Gupta via .NET 247
  • Start date Start date
A

Anuj Gupta via .NET 247

Can anyone please suggest 'why it is must to have a defualt constructor while serializing a class using XMLSerializer'?
 
Because the XmlSerializer deserializes an object by instantiating it (hence
the need for a default constructor) and then populating all of its
properties that can be written to. That's why the XmlSerializer won't
retain state for private members or any property that cannot be written to.

If you need an object that completely maintains its state (private members)
and does not rely on a default constructor, you should look at the
BinaryFormatter or the SoapFormatter. These can be found respectively in
the System.Runtime.Serialization.Formatters.Binary or
System.Runtime.Serialization.Formatters.Soap namespaces.

--
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com

Anuj Gupta via .NET 247 said:
Can anyone please suggest 'why it is must to have a defualt constructor
while serializing a class using XMLSerializer'?
 
Back
Top