Here is the code I am using. It looks roughly the same as yours. Haven't
actually tried calling ser, deser, ser again, so it may behave the same.
Give it a shot.
HTH,
Greg
Public Shared Function LoadSettings() As UserSettings
Dim mySettings As New UserSettings
Dim s As String =
Environment.GetFolderPath(System.Environment.Speci alFolder.ApplicationData)
s &= "\PCO\pco.bin"
If File.Exists(s) Then
Dim streamOut As FileStream
Try
Dim formatter As New BinaryFormatter
streamOut = New FileStream(s, FileMode.Open,
FileAccess.Read)
mySettings = CType(formatter.Deserialize(streamOut),
UserSettings)
Catch
Finally
streamOut.Close()
End Try
End If
Return mySettings
End Function
Public Shared Sub SaveSettings(ByVal mySettings As UserSettings)
Dim s As String =
Environment.GetFolderPath(System.Environment.Speci alFolder.ApplicationData)
s &= "\PCO"
If Not Directory.Exists(s) Then
Directory.CreateDirectory(s)
End If
s &= "\pco.bin"
Dim formatter As New BinaryFormatter
Dim streamIn As New FileStream(s, FileMode.Create,
FileAccess.Write)
formatter.Serialize(streamIn, mySettings)
streamIn.Close()
End Sub
"andreas" <an*****@pandora.be> wrote in message
news:IT**********************@phobos.telenet-ops.be...
Info for the question
As value for the arrSdList i have a class instance defined as
<serializable> public class clsPerson
"andreas" <an*****@pandora.be> schreef in bericht
news:YL*********************@phobos.telenet-ops.be...
Hi,
if have a object arrSdList of type SortedList for serialization and
deserialization
there are two subs for doing this
Public Sub deser
Dim Formatter As BinaryFormatter = New BinaryFormatter()
Dim ReadFile As FileStream
ReadFile = File.OpenRead(FilePad)
arrSdList = CType(Formatter.Deserialize(ReadFile), SortedList)
ReadFile.Close()
End Sub
Public Sub ser
Dim Formatter As BinaryFormatter = New BinaryFormatter()
Dim SaveFile As FileStream
SaveFile = File.OpenWrite(FilePad)
SaveFile.Seek(0, SeekOrigin.End)
Formatter.Serialize(SaveFile, arrSdList)
SaveFile.Close()
End Sub
when i do
ser
deser
there is no exception message
but when i do
ser
deser
ser
i get the exception message for the second ser :
Binary stream does not contain a valid BinaryHeader, 0 possible causes,
invalid stream or object version change between serialization and
deserialization.
what is wrong with the subs ?
who can help me ?