473,327 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

serialization

I have a class that has been serialized and saved to disk. I am trying to
deserialize it back into the same class which now has an extra private
member. It will not deserialize because its signature has changed so I
added:

Protected Sub New(ByVal info As SerializationInfo, ByVal context As
StreamingContext)
End Sub

to my new class so that I can specify custom deserialization however it does
not get called by the deserialization formatter if I don't specify that the
class implements iSerializable. When I do implement iSerializable in my new
class then the class signature no longer matches the old class so an error
gets raised. Seems like I am stuck. Maybe if I had implemented iSerializable
from the beginning in the old class this might have worked but what should I
do now?

Perry
Nov 20 '05 #1
5 1690
Perecli,
One of the following 3 part MSDN Magazine column on Serialization covers
this problem and how to correct it!

http://msdn.microsoft.com/msdnmag/issues/02/04/net/
http://msdn.microsoft.com/msdnmag/issues/02/07/net/
http://msdn.microsoft.com/msdnmag/issues/02/09/net/

I hope you read all three, as they are invaluable for implementing
Serialization in .NET!

You are correct in needing to implement ISerializable and give the special
constructor, in addition to implementing ISerializable you need to 'Override
the type when deserializing', which is covered in the 3rd article. It
involves creating a new binder class that changes the type for version 1.0
objects to version 2.0 object.

Hope this helps
Jay

"Perecli Manole" <Pe*****@dslextreme.com> wrote in message
news:e$**************@TK2MSFTNGP11.phx.gbl...
I have a class that has been serialized and saved to disk. I am trying to
deserialize it back into the same class which now has an extra private
member. It will not deserialize because its signature has changed so I
added:

Protected Sub New(ByVal info As SerializationInfo, ByVal context As
StreamingContext)
End Sub

to my new class so that I can specify custom deserialization however it does not get called by the deserialization formatter if I don't specify that the class implements iSerializable. When I do implement iSerializable in my new class then the class signature no longer matches the old class so an error
gets raised. Seems like I am stuck. Maybe if I had implemented iSerializable from the beginning in the old class this might have worked but what should I do now?

Perry

Nov 20 '05 #2
Yes, I have read all three articles on your previous recomendation. This is
what got me so far but it is still not working. This is how my
deserialization binder class looks:

Private Class VersionDeserializationBinder
Inherits SerializationBinder

Public Overrides Function BindToType(ByVal assemblyName As
String, ByVal typeName As String) As Type
Return Type.GetType(String.Format("{0}, {1}", typeName,
Reflection.Assembly.GetExecutingAssembly.FullName) )
End Function
End Class

Still have the same problem mentioned in my initial post.

Perry

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:eA*************@TK2MSFTNGP11.phx.gbl...
Perecli,
One of the following 3 part MSDN Magazine column on Serialization covers
this problem and how to correct it!

http://msdn.microsoft.com/msdnmag/issues/02/04/net/
http://msdn.microsoft.com/msdnmag/issues/02/07/net/
http://msdn.microsoft.com/msdnmag/issues/02/09/net/

I hope you read all three, as they are invaluable for implementing
Serialization in .NET!

You are correct in needing to implement ISerializable and give the special
constructor, in addition to implementing ISerializable you need to 'Override the type when deserializing', which is covered in the 3rd article. It
involves creating a new binder class that changes the type for version 1.0
objects to version 2.0 object.

Hope this helps
Jay

"Perecli Manole" <Pe*****@dslextreme.com> wrote in message
news:e$**************@TK2MSFTNGP11.phx.gbl...
I have a class that has been serialized and saved to disk. I am trying to deserialize it back into the same class which now has an extra private
member. It will not deserialize because its signature has changed so I
added:

Protected Sub New(ByVal info As SerializationInfo, ByVal context As
StreamingContext)
End Sub

to my new class so that I can specify custom deserialization however it does
not get called by the deserialization formatter if I don't specify that

the
class implements iSerializable. When I do implement iSerializable in my

new
class then the class signature no longer matches the old class so an error gets raised. Seems like I am stuck. Maybe if I had implemented

iSerializable
from the beginning in the old class this might have worked but what

should I
do now?

Perry


Nov 20 '05 #3
Perecli,
Not sure what to offer, as your code does not appear at all like the sample
in Figure 3 of article 3.

Are all the types you are deserializing in the same assembly as the
VersionDeserializationBinder class?

What you may want to do is put a break point in BindToType to see what is
coming in and what is going out, just to be certain that you have
implemented it correctly.

Hint, I suspect the routine is called for types in the System namespace,
such as System.String.

Hope this helps
Jay

"Perecli Manole" <Pe*****@dslextreme.com> wrote in message
news:e5**************@tk2msftngp13.phx.gbl...
Yes, I have read all three articles on your previous recomendation. This is what got me so far but it is still not working. This is how my
deserialization binder class looks:

Private Class VersionDeserializationBinder
Inherits SerializationBinder

Public Overrides Function BindToType(ByVal assemblyName As
String, ByVal typeName As String) As Type
Return Type.GetType(String.Format("{0}, {1}", typeName,
Reflection.Assembly.GetExecutingAssembly.FullName) )
End Function
End Class

Still have the same problem mentioned in my initial post.

Perry

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message news:eA*************@TK2MSFTNGP11.phx.gbl...
Perecli,
One of the following 3 part MSDN Magazine column on Serialization covers
this problem and how to correct it!

http://msdn.microsoft.com/msdnmag/issues/02/04/net/
http://msdn.microsoft.com/msdnmag/issues/02/07/net/
http://msdn.microsoft.com/msdnmag/issues/02/09/net/

I hope you read all three, as they are invaluable for implementing
Serialization in .NET!

You are correct in needing to implement ISerializable and give the special
constructor, in addition to implementing ISerializable you need to

'Override
the type when deserializing', which is covered in the 3rd article. It
involves creating a new binder class that changes the type for version 1.0 objects to version 2.0 object.

Hope this helps
Jay

"Perecli Manole" <Pe*****@dslextreme.com> wrote in message
news:e$**************@TK2MSFTNGP11.phx.gbl...
I have a class that has been serialized and saved to disk. I am trying to deserialize it back into the same class which now has an extra private
member. It will not deserialize because its signature has changed so I
added:

Protected Sub New(ByVal info As SerializationInfo, ByVal context As
StreamingContext)
End Sub

to my new class so that I can specify custom deserialization however
it does
not get called by the deserialization formatter if I don't specify
that the
class implements iSerializable. When I do implement iSerializable in
my new
class then the class signature no longer matches the old class so an

error gets raised. Seems like I am stuck. Maybe if I had implemented

iSerializable
from the beginning in the old class this might have worked but what

should
I
do now?

Perry



Nov 20 '05 #4
> Not sure what to offer, as your code does not appear at all like the
sample
in Figure 3 of article 3.
The sample shows how to deserialize a class with one name into a class with
a differet name. This will not work for my application because all the code
in my app references the class by name.

For example. I serialized a class with the name "MyClass" and saved it to
disk. After this I modified "MyClass" by adding a private member. Now I want
to deserialize the class on disk back into the same class "MyClass", not
another class as is shown in the example.
Are all the types you are deserializing in the same assembly as the
VersionDeserializationBinder class?
Yes
What you may want to do is put a break point in BindToType to see what is
coming in and what is going out, just to be certain that you have
implemented it correctly.
I have done this and all is OK. The version of the old class is changed to
that of the current assembly.
Hint, I suspect the routine is called for types in the System namespace,
such as System.String.
The problem is that when I add "Implements ISerializable" to my new class,
with no other changes as compared to the old class that was serialized. The
deserializer complains that it can't deserialize it to the new class. Keep
in mind that my old class did not implement ISerializable.

Perry
"Perecli Manole" <Pe*****@dslextreme.com> wrote in message
news:e5**************@tk2msftngp13.phx.gbl...
Yes, I have read all three articles on your previous recomendation. This

is
what got me so far but it is still not working. This is how my
deserialization binder class looks:

Private Class VersionDeserializationBinder
Inherits SerializationBinder

Public Overrides Function BindToType(ByVal assemblyName As
String, ByVal typeName As String) As Type
Return Type.GetType(String.Format("{0}, {1}", typeName,
Reflection.Assembly.GetExecutingAssembly.FullName) )
End Function
End Class

Still have the same problem mentioned in my initial post.

Perry

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in

message
news:eA*************@TK2MSFTNGP11.phx.gbl...
Perecli,
One of the following 3 part MSDN Magazine column on Serialization covers this problem and how to correct it!

http://msdn.microsoft.com/msdnmag/issues/02/04/net/
http://msdn.microsoft.com/msdnmag/issues/02/07/net/
http://msdn.microsoft.com/msdnmag/issues/02/09/net/

I hope you read all three, as they are invaluable for implementing
Serialization in .NET!

You are correct in needing to implement ISerializable and give the special constructor, in addition to implementing ISerializable you need to

'Override
the type when deserializing', which is covered in the 3rd article. It
involves creating a new binder class that changes the type for version 1.0 objects to version 2.0 object.

Hope this helps
Jay

"Perecli Manole" <Pe*****@dslextreme.com> wrote in message
news:e$**************@TK2MSFTNGP11.phx.gbl...
> I have a class that has been serialized and saved to disk. I am trying
to
> deserialize it back into the same class which now has an extra
private > member. It will not deserialize because its signature has changed so I > added:
>
> Protected Sub New(ByVal info As SerializationInfo, ByVal context As
> StreamingContext)
> End Sub
>
> to my new class so that I can specify custom deserialization however

it does
> not get called by the deserialization formatter if I don't specify that the
> class implements iSerializable. When I do implement iSerializable in my new
> class then the class signature no longer matches the old class so an

error
> gets raised. Seems like I am stuck. Maybe if I had implemented
iSerializable
> from the beginning in the old class this might have worked but what

should
I
> do now?
>
> Perry
>
>



Nov 20 '05 #5
Perecli,
Not sure what to offer, I gave you all the tricks I know on the subject.

Asking in either microsoft.public.dotnet.framework or
microsoft.public.dotnet.framework.clr might find someone with more knowledge
on Serialization.

Good luck,
Jay

"Perecli Manole" <Pe*****@dslextreme.com> wrote in message
news:e5**************@TK2MSFTNGP12.phx.gbl...
Not sure what to offer, as your code does not appear at all like the sample
in Figure 3 of article 3.


The sample shows how to deserialize a class with one name into a class

with a differet name. This will not work for my application because all the code in my app references the class by name.

For example. I serialized a class with the name "MyClass" and saved it to
disk. After this I modified "MyClass" by adding a private member. Now I want to deserialize the class on disk back into the same class "MyClass", not
another class as is shown in the example.
Are all the types you are deserializing in the same assembly as the
VersionDeserializationBinder class?
Yes
What you may want to do is put a break point in BindToType to see what is
coming in and what is going out, just to be certain that you have
implemented it correctly.


I have done this and all is OK. The version of the old class is changed to
that of the current assembly.
Hint, I suspect the routine is called for types in the System namespace,
such as System.String.


The problem is that when I add "Implements ISerializable" to my new class,
with no other changes as compared to the old class that was serialized.

The deserializer complains that it can't deserialize it to the new class. Keep
in mind that my old class did not implement ISerializable.

Perry
"Perecli Manole" <Pe*****@dslextreme.com> wrote in message
news:e5**************@tk2msftngp13.phx.gbl...
Yes, I have read all three articles on your previous recomendation. This
is
what got me so far but it is still not working. This is how my
deserialization binder class looks:

Private Class VersionDeserializationBinder
Inherits SerializationBinder

Public Overrides Function BindToType(ByVal assemblyName As
String, ByVal typeName As String) As Type
Return Type.GetType(String.Format("{0}, {1}",
typeName, Reflection.Assembly.GetExecutingAssembly.FullName) )
End Function
End Class

Still have the same problem mentioned in my initial post.

Perry

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:eA*************@TK2MSFTNGP11.phx.gbl...
> Perecli,
> One of the following 3 part MSDN Magazine column on Serialization

covers > this problem and how to correct it!
>
> http://msdn.microsoft.com/msdnmag/issues/02/04/net/
> http://msdn.microsoft.com/msdnmag/issues/02/07/net/
> http://msdn.microsoft.com/msdnmag/issues/02/09/net/
>
> I hope you read all three, as they are invaluable for implementing
> Serialization in .NET!
>
> You are correct in needing to implement ISerializable and give the

special
> constructor, in addition to implementing ISerializable you need to
'Override
> the type when deserializing', which is covered in the 3rd article. It > involves creating a new binder class that changes the type for version 1.0
> objects to version 2.0 object.
>
> Hope this helps
> Jay
>
> "Perecli Manole" <Pe*****@dslextreme.com> wrote in message
> news:e$**************@TK2MSFTNGP11.phx.gbl...
> > I have a class that has been serialized and saved to disk. I am trying to
> > deserialize it back into the same class which now has an extra private > > member. It will not deserialize because its signature has changed
so I > > added:
> >
> > Protected Sub New(ByVal info As SerializationInfo, ByVal context
As > > StreamingContext)
> > End Sub
> >
> > to my new class so that I can specify custom deserialization however it
> does
> > not get called by the deserialization formatter if I don't specify

that
> the
> > class implements iSerializable. When I do implement iSerializable
in my
> new
> > class then the class signature no longer matches the old class so

an error
> > gets raised. Seems like I am stuck. Maybe if I had implemented
> iSerializable
> > from the beginning in the old class this might have worked but what should
> I
> > do now?
> >
> > Perry
> >
> >
>
>



Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined...
1
by: andrewcw | last post by:
There is an error in XML document (1, 2). I used XML spy to create the XML and XSD. When I asked to have the XML validated it said it was OK. I used the .net SDK to generate the class. I have...
3
by: Aaron Clamage | last post by:
Hi, I'm not sure that if this is the right forum, but any help would be greatly appreciated. I am porting some java serialization code to c# and I can't figure out the correct way to do it. ...
6
by: Uttam | last post by:
Hello, We are at a very crucial decision making stage to select between .Net and Java. Our requirement is to download a class at runtime on the client computer and execute it using remoting or...
3
by: Alexander | last post by:
When i store rule on PC with .NET.SP1 i cant restore them from PC without SP1. An i get this Error: System.Runtime.Serialization.SerializationException: Possible Version mismatch. Type...
4
by: mijalko | last post by:
Hi, I have inherited my class from System.Drawing.Printing.PrintDocument and I wish to serialize this object using XmlSerializer. And I get exception "There was an error reflecting type ...". If I...
5
by: Nikola Skoric | last post by:
I ran in Mono a program developed on .NET Framework 2.0 and it ran OK until I tried to desirialize a object. There the program died abruptly dumping this: System.ArgumentOutOfRangeException:...
0
by: bharathreddy | last post by:
Before going to that i want to say few thing on serialization : Serialization is the process of converting an object into a form that can be readily transported. For example, you can serialize an...
1
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
2
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.