Deserialize class with more members

FredjeV

Member
Joined
Dec 16, 2003
Messages
5
Hi,

I have serailized a class with 44 members. After changing the class I want to deserialize the old class (on disk) to the new class.
This gives me an deserialization error that the old only has 44 members instead of 46.

How can i deserialize this file into the new class. Please help me with some VB.NET code because C# is to difficult for me.

Fred
 
VBAHole22 said:
Why not post some of the relevant code that you are using for the serialization?

The Serailize and Deserialize code:

Sub Serializeer(ByVal obj As Object, ByVal File As String, ByVal Mode As FileMode)
Dim ext As String
Dim fm As IFormatter
Dim fs As FileStream

fm = New BinaryFormatter()
Try
fs = New FileStream(File, Mode)
FileMode.Create: vorige mag overschreven worden
FileMode.CreateNew: als al bestaat ->IOException

fm.Serialize(fs, obj)
fs.Close()
Catch ex As IOException
MessageBox.Show(ex.Message)
End Try
End Sub

Function Deserializeer(ByVal File As String) As colWater
Dim ext As String
Dim obj As Object = Nothing
Dim fm As IFormatter
Dim fs As FileStream = Nothing

Try
fm = New BinaryFormatter()
fs = New FileStream(File, FileMode.Open)
obj = fm.Deserialize(fs)
fs.Close()
Catch ex As FileNotFoundException
MessageBox.Show(ex.Message)
Catch ex As SerializationException
verion mismatch can be solved: http://msdn.microsoft.com/msdnmag/issues/02/09/net/
If Not fs Is Nothing Then fs.Close()
MessageBox.Show(ex.Message)
Catch ex As FormatException
MessageBox.Show(ex.Message)
End Try
Return CType(obj, colWater)
End Function
 
You need a Serialized object to Deserialize. In your function your Deserializing an object. Also, consider using one function to serialize and deserialize.
 
Back
Top