Hi,
I have a class library in which I have classes which implement
ISerializable. They all have GetObjectData implementations and
constructors to support deserialization.
In unit testing this library, I discovered that my classes were being
serialized by XmlSerializer using the default behavior of traversing the
public g/s properties.
My unit test app is a console program and nothing is being downloaded.
At first I set breakpoints to trap the process, but when that failed, I
altered the GetObjectData() method in one class to cause the generation
recognizably-inaccurate but still-legal xml data by omitting calling
AddValue for a couple properties.
Sure enough, XmlSerializer blithely generated Xml that had the omitted
properties proving my GetObjectData method was not being called. The
class I isolated on to test this is a public base class.
Anyone know what the problem could be? I can attach the code but
really, it's no different than the thousand basic examples out there for
implementing ISerializable.
Any help would be dearly appreciated!
======================
blackbox testing prerequisites:
1 white box
1 black marker
Marc Gravell - 28 Aug 2007 21:14 GMT
There are 2 primary (and disparate) forms of serialization; binary-
based and xml-based. The BinarySerializer uses the first, the
XmlSerializer and DataContractSerializer make use of the second. You
can customise binary serialization by using ISerializable (and a
custom ctor) [and markers like NonSerializedAttribute]; however, you
customise xml-serialization using IXmlSerializable [and markers like
XmlElementAttribute, XmlIgnoreAttribute, or DataMemberAttribute etc
for data-contracts).
So you need to look into IXmlSerializable. Sorry.
Marc
RRB - 28 Aug 2007 21:34 GMT
Hi Marc,
Thanks for the reply (and the condolences).
A pox on every tutorial out there showing the same basic ISerializable
example without mentioning that it's not recognized by XmlSerializer.
But otoh, I guess the lack of support for specifying attributes should
have been my first clue.
======================
blackbox testing prerequisites:
1 white box
1 black marker