P
Pavel Pavel
I have 2 solution to deserialize ArrayList which contains objects
I am using for this MemoryStream, but MemoryStream is not functional - I
receive always error
#End of Stream encountered before parsing was completed.#
The second solution is functionall - I am using in this solution
FileStream - everything works fine !!
I want to use MemoryStream instead of FileStrem
Can somebody tells me where I have problem ?
I am using the same source: byte array Dim bytes() As Byte
Thanks
#################### First solution with ERROR ############
Dim bytes() As Byte = row("PANEL_DATA") 'DataRow, column PANEL_DATA
Dim bFormatter As New BinaryFormatter()
Dim ms As MemoryStream
Dim b As Byte
ms = New MemoryStream()
ms.SetLength(bytes.Length)
Dim i As Int32
For i = 0 To bytes.Length - 1
ms.WriteByte(bytes(i))
Next
Try
########### in this line is error ###############
Me.objList = bFormatter.Deserialize(ms)
Catch ex As Exception
ms.Close()
gShowError(ex, "LoadControlsSer - deserialize")
End Try
ms.Close()
#################### Second solution - working solution ############
Dim ms As New MemoryStream()
Dim bFormatter As New BinaryFormatter()
ms.Write(bytes, 0, bytes.Length)
Dim stream11 As Stream = New FileStream("C:\MyFile.bin", FileMode.Create,
FileAccess.Write, FileShare.None)
stream11.Write(bytes, 0, bytes.Length)
stream11.Close()
Try
Dim formatter As BinaryFormatter = New BinaryFormatter()
Dim stream22 As Stream = New FileStream("C:\MyFile.bin", FileMode.Open,
FileAccess.Read, FileShare.Read)
Me.objList = formatter.Deserialize(stream22)
stream22.Close()
Catch ex As Exception
gShowError(ex, "LoadControlsSer")
Return False
End Try
Return True
Tomas Oplt
Tel: 603 171893
I am using for this MemoryStream, but MemoryStream is not functional - I
receive always error
#End of Stream encountered before parsing was completed.#
The second solution is functionall - I am using in this solution
FileStream - everything works fine !!
I want to use MemoryStream instead of FileStrem
Can somebody tells me where I have problem ?
I am using the same source: byte array Dim bytes() As Byte
Thanks
#################### First solution with ERROR ############
Dim bytes() As Byte = row("PANEL_DATA") 'DataRow, column PANEL_DATA
Dim bFormatter As New BinaryFormatter()
Dim ms As MemoryStream
Dim b As Byte
ms = New MemoryStream()
ms.SetLength(bytes.Length)
Dim i As Int32
For i = 0 To bytes.Length - 1
ms.WriteByte(bytes(i))
Next
Try
########### in this line is error ###############
Me.objList = bFormatter.Deserialize(ms)
Catch ex As Exception
ms.Close()
gShowError(ex, "LoadControlsSer - deserialize")
End Try
ms.Close()
#################### Second solution - working solution ############
Dim ms As New MemoryStream()
Dim bFormatter As New BinaryFormatter()
ms.Write(bytes, 0, bytes.Length)
Dim stream11 As Stream = New FileStream("C:\MyFile.bin", FileMode.Create,
FileAccess.Write, FileShare.None)
stream11.Write(bytes, 0, bytes.Length)
stream11.Close()
Try
Dim formatter As BinaryFormatter = New BinaryFormatter()
Dim stream22 As Stream = New FileStream("C:\MyFile.bin", FileMode.Open,
FileAccess.Read, FileShare.Read)
Me.objList = formatter.Deserialize(stream22)
stream22.Close()
Catch ex As Exception
gShowError(ex, "LoadControlsSer")
Return False
End Try
Return True
Tomas Oplt
Tel: 603 171893