.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

IXmlSerializable vs. ISerializable

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :ADO.Net

I am working on a project which uses the IxmlSerializable interface for serializing/deserializing of complex data to a persisted file. I'm not sure why the prior development team chose IXmlSerializable as it seems to have led to some very klunky code paths. Basically, classes evolved properties were added, deleted, had name changes, changed types etc. This was handled by requiring the developer to version a serialized type each time one of these changes were made:

if(_version < 5)


if(_version < 4)



else if(_version < 6)




hopefully, you get the picture.

The big problem is of course that the users have data which is unique to them, such that when they report a serialization issue, which is frequent, we have to have them send in their entire data sets to reproduce the issue.

I am tempted to recommend that we scrap the IXmlSerializable implementation in favour of ISerializable. I would be using a BinaryFormatter. In my testing, it is much more forgiving in how it handles changes to serialized classes, and it is much more performant. it doesn't appear that I have to continually resort to ugly switch code when I make basic changes. While I haven't tested it, I understand that it handles Collections of objects where IXmlSerializable does not. 

Yes, w

View Complete Post

More Related Resource Links

How to Implement ISerializable using Reflection

I trying to serialize my business object manually by implementing the ISerializable interface, but is there any way to implement the Iserialazble in the base class and no need to tell the Derived class to which fields to Serialize or not. I tried it to find the source on the internet and able to get a similar code in which base class loops through each derived classes and their base classes and so on, to find out the private field members and add them to serializationinfo parameter, but that code also serializes the events which is causing error for my code, so I want to know how do I tell that only serializes the fields and skip all the events...

Serializaing/deserializing XOMLs with custom activities that have properties of ISerializable types

I have custom activities that have dependency properties of types that implement ISerializable. When they are serialized/deserialized to XOML, the ISerializable-implied functionality is ignored and the standard reflection-based SerializableAttribute behavior is invoked. This poses a serious problem since the types require precise control over their serialization to ensure that proper internal state is maintained across serialization boundaries. I am aware of the WF custom serialization methods as mentioned in Tom Lakes' blog post, but they seem to require the DesignerSerializerAttribute attribute on all custom types. This is a problem because the types are business objects shared across many (non-WF) applications and they are part of a seperate code base to which I have no access. Is there a different method for getting custom serialization? And what is the reasoning behind the WF team choosing to ignore the very basic ISerializable attribute which is supported by every other .NET API across the framework? Thanks in advance.

ISerializable Support in Data Contracts

Hi, We are migrating a bunch of services that pass typed datasets to instead use data contracts.  The types translate to data contracts really well -- basic properties and collections of other data contract types.  And everything works fine -- except for binary serialization performance compared to typed datasets.  Datasets have a pretty well-optimized serialization mechanism so we went to work and implemented ISerializable for our data contracts.  That custom serialization meets or beats the dataset serialization, so we are happy about that. The problem is that you can't have a type decorated with the DataContract attribute that also implements ISerializable.  I was hoping there was some way to host a netTcp binding that would use our custom serialization while also being able to host the same service using Http and the regular Data Contract Serializer (and other WCF interop goodness).  But if a data contract can't implement ISerializable, then I have to duplicate my types (and therefore my contracts) and figure out some wacky inheritance scheme to avoid duplicating the service code as well. Is there some way to configure a host to use a custom binary serializer (doesn't *have* to be ISerializable) while preserving the abilty to use the standard data contract features over Http? Thanks, -ErikErik Johnson

Serializing a List of ISerializable


I am guessing this is a common problem, and I just haven't been able to find the answer yet.

I have a hierarchical class structure of ISerializable objects “ClassX”, “ClassY” inherits abstract “AbstractClassZ”, and another ISerializable class “ClassA” with a list of “List<AbstractClassZ>”.  On my method call ISerializable.GetObjectData info successfully has a “List<AbstractClassZ>” with values.  I do this with a simple info.AddValue(“List”, AbstractClassZList);.  Now on my de-serializing constructor call, info has an instance of a list, but all the values are null.  Do I have the Serialized each value in the list, or is there another way?


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend