Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2007

Tip: Looking for answers? Try searching our database.

Help! ISerializable not being detected by XmlSerializer

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RRB - 28 Aug 2007 20:53 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.