Basics of Serialization in .NET Framework 3.0
page 5 of 6
by Uday Denduluri
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 28011/ 62

Comparing Basic serialization with Custom serialization

Using basic serialization we can have an attribute "Serializable" at the class level. Using basic serialization, it is up to the .NET Framework to take care of the serialization and de-serialization. But the problem with this type of serialization is that we cannot have control over the serialization algorithm. Another major issue with basic serialization is that we have versioning issues like "System.Runtime.Serialization.SerializationException" Possible Version mismatch. But basic serialization is the easiest way for serialization.

On other hand custom serialization gives us more control. As we have seen in listing 1 and 2, we can implement the interface ISerializable which gives us more control over the serialization algorithm. We can also avoid the serialization exceptions with the custom serialization. Apart from these, we have 4 attributes when applied to methods they are called in the process of serialization. Let us see each one of them in detail.

·         OnDeserializedAttribute – This attribute when put on a method, the method gets fired when the de-serialization is completely done.

·         OnDeserializingAttribute – When applied on a method this method is called during de-serialization of an object.

·         OnSerializedAttribute – When applied on a method this method gets fired after the serialization process takes place.

·         OnSerializingAttribute – When applied on a method this is fired during the serialization process.

We can get maximum control over serialization and deserialization process using the attributes.


View Entire Article

User Comments

Title: Incorrect information   
Name: Bob
Date: 2008-04-22 6:00:25 PM
Comment:
this article states that :
----------------------------
NonSerializedAttribute – If a class is marked as Serializable then all the properties can be serialized. For example, if we have a User object that has properties like user name, password [not in encrypted format], role of the user, etc. then such kinds of crucial information can be leaked out if serialized. We have the NonSerializable attribute that helps us in marking a property as not serializable.
--------------------------------
however, this is totally incorrect. You cannot use the NonSerializable attribute on a Property. It is for fields only, and will generate a compiler error.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-24 8:40:33 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search