If you implement the ISerializable interface, this is not going to give
you the same semantics as using IXmlSerializer.
When using IXmlSerializer, it is going to serialize all public
properties. The problem with this is that if one of the properties exposes
an interface type, the Xml serialization engine doesn't know what the
appropriate implementation type should be (since it can be anything that
implements it) and won't know what to create when re-hydrating the object.
When you use the serialization engine, you are serializing the fields
that are in the object. Because of that, exposing interfaces on properties
doesn't matter, since the serialization engine is always going to dig into
the type and get the fields.
However, you have to make sure that all fields are of types that have
the Serializable attribute applied to them, which is the case here.
I would recommend using the Serialization framework (not the Xml
serialization framework) to serialize these types, and make sure that your
components site is either serializable, or don't serialize the reference to
the site in your custom ISerializable implementation.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
<mi*****@gmail.comwrote in message
news:11**********************@y66g2000hsf.googlegr oups.com...
Hi,
I have inherited my class from System.Drawing.Printing.PrintDocument
and I wish to serialize this object using XmlSerializer. And I get
exception "There was an error reflecting type ...". If I look at
innerException it says: "Cannot serialize member
'System.ComponentModel.Component.Site' of type
'System.ComponentModel.ISite'.
OK it is problem to serialize all data so I'll implement my
Serialization. I implemented ISerializable interface, but the problem
is the same. Shouldn't implementation of ISerializable override
default serialization and allow me to serialize MyPrintDocument class?
And have you any suggestion how can I solve this problem?