G
Guest
I'm saving an object to isolated storage to preserve user session
information. Over time I add new variables to the session object. This breaks
the deserialization of the object with an
System.Runtime.Serialization.SerializationException. The exception message
reads "Possible Version mismatch. Type
raptSessionData.Aralan.dbLibrary.raptSessionData has 3 members,
number of members deserialized is 2." Cool! It sees what the problem is.
How do I amend the code below to deserialize the two data members stored in
the old version of the object?
Thanks in advance for your help!
Sub restore()
Dim isf As IsolatedStorageFile, needsInit As Boolean = False
isf = IsolatedStorageFile.GetUserStoreForAssembly()
If isf.GetFileNames(RAPTSESSION_FLNM).Length > 0 Then
Dim isfs As IsolatedStorageFileStream, binFmt As BinaryFormatter,
rsd As raptSessionData
isfs = New IsolatedStorageFileStream(RAPTSESSION_FLNM,
FileMode.Open, isf)
binFmt = New BinaryFormatter
Try
rsd = DirectCast(binFmt.Deserialize(isfs), raptSessionData)
Me.setTo(rsd)
Catch ex As System.Runtime.Serialization.SerializationException
needsInit = True
Catch ex As Exception
Throw ex
Finally
isfs.Close()
End Try
Else
needsInit = True
End If
If needsInit Then
Me.initSessionVariables()
End If
isf.Close()
End Sub
Hal Heinrich
VP Technology
Aralan Solutions Inc.
information. Over time I add new variables to the session object. This breaks
the deserialization of the object with an
System.Runtime.Serialization.SerializationException. The exception message
reads "Possible Version mismatch. Type
raptSessionData.Aralan.dbLibrary.raptSessionData has 3 members,
number of members deserialized is 2." Cool! It sees what the problem is.
How do I amend the code below to deserialize the two data members stored in
the old version of the object?
Thanks in advance for your help!
Sub restore()
Dim isf As IsolatedStorageFile, needsInit As Boolean = False
isf = IsolatedStorageFile.GetUserStoreForAssembly()
If isf.GetFileNames(RAPTSESSION_FLNM).Length > 0 Then
Dim isfs As IsolatedStorageFileStream, binFmt As BinaryFormatter,
rsd As raptSessionData
isfs = New IsolatedStorageFileStream(RAPTSESSION_FLNM,
FileMode.Open, isf)
binFmt = New BinaryFormatter
Try
rsd = DirectCast(binFmt.Deserialize(isfs), raptSessionData)
Me.setTo(rsd)
Catch ex As System.Runtime.Serialization.SerializationException
needsInit = True
Catch ex As Exception
Throw ex
Finally
isfs.Close()
End Try
Else
needsInit = True
End If
If needsInit Then
Me.initSessionVariables()
End If
isf.Close()
End Sub
Hal Heinrich
VP Technology
Aralan Solutions Inc.