Deserializing after class has been modified.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

am trying to find a way to backward support serialized files of older version

Example:
Given a class

class MyClass
{
int a;
int b;
}

Serialize MyClass using SoapFormatter to myclass.bin

add int c; to MyClass

class MyClass
{
int a;
int b;
int c;//newly added
}

If i deserialize using SoapFormatter now from myclass.bin (created before
adding int c)... exception will thrown..

is there anyway to support 'older' version of serialized soap files besides
manually parsing it?

many thanks
tham
 
In .NET 1.1 you can't (well there's a trick, keep reading).
In .NET 2.0 Soapformatter you're out of luck, BinaryFormatter will work
using an new OptionalAttribute.

You can get this behavior by implementing ISerialization in .NET 1.1 and use
reflection to read stuff out of the SerializationInfo info variable.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
 
Sorry that was ISerializable.


Sahil Malik said:
In .NET 1.1 you can't (well there's a trick, keep reading).
In .NET 2.0 Soapformatter you're out of luck, BinaryFormatter will work
using an new OptionalAttribute.

You can get this behavior by implementing ISerialization in .NET 1.1 and
use
reflection to read stuff out of the SerializationInfo info variable.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
 
Back
Top