Help! ISerializable not being detected by XmlSerializer

R

RRB

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
 
M

Marc Gravell

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
 
R

RRB

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top