M
Marc
Hi,
I am trying to serialize a data structure -- a list (of custom class)
-- in one application, then read it in with another application. My
serialize and deserialize subs are in a module that is shared between
the two applications, so they are using exactly the same code (this
module also contains the class, so I am certain the class code is the
same)
The code I'm using is quite simple, so I'm not sure where I'm going
wrong:
Private AllOrders as List (Of CustomOrder)
Function SerializeOrders(ByVal Path As String) As Integer
'Writes (serializes) All Orders to disk at given path
Dim myFileStream As New System.IO.FileStream(Path,
System.IO.FileMode.Create)
Dim MyFormatter As New
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
If (AllOrders IsNot Nothing) Then
MyFormatter.Serialize(myFileStream, AllOrders)
End If
myFileStream.Close()
End Function
Function DeserializeOrders(ByVal path As String) As Integer
' Reads list of orders from given path and OVERWRITES AllOrders
Dim myFileStream As New System.IO.FileStream(path,
System.IO.FileMode.OpenOrCreate)
Dim MyFormatter As New
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
Dim GenericObject As Object
Try
GenericObject = MyFormatter.Deserialize(myFileStream)
AllOrders = CType(GenericObject, List(Of TEOrder))
Catch ex As Exception
Finally
myFileStream.Close()
End Try
End Function
No exception is ever raised. When I serialize, I can check the file
and it contains data (which means that serialization is working).
However, when I deserialize in the other application, I get 0 objects.
A final observation: serialization & deserialization work fine when
done within the same application. It is only between applications
that I have the problem.
Help?
BTW I would be interested in using the SOAPFormatter but I can't find
it in VB.NET. I read about it online but don't see it available.
What do I need to do to make that available to me? (I would much
prefer human-readable output when I serialize)
Thanks,
Marc
I am trying to serialize a data structure -- a list (of custom class)
-- in one application, then read it in with another application. My
serialize and deserialize subs are in a module that is shared between
the two applications, so they are using exactly the same code (this
module also contains the class, so I am certain the class code is the
same)
The code I'm using is quite simple, so I'm not sure where I'm going
wrong:
Private AllOrders as List (Of CustomOrder)
Function SerializeOrders(ByVal Path As String) As Integer
'Writes (serializes) All Orders to disk at given path
Dim myFileStream As New System.IO.FileStream(Path,
System.IO.FileMode.Create)
Dim MyFormatter As New
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
If (AllOrders IsNot Nothing) Then
MyFormatter.Serialize(myFileStream, AllOrders)
End If
myFileStream.Close()
End Function
Function DeserializeOrders(ByVal path As String) As Integer
' Reads list of orders from given path and OVERWRITES AllOrders
Dim myFileStream As New System.IO.FileStream(path,
System.IO.FileMode.OpenOrCreate)
Dim MyFormatter As New
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
Dim GenericObject As Object
Try
GenericObject = MyFormatter.Deserialize(myFileStream)
AllOrders = CType(GenericObject, List(Of TEOrder))
Catch ex As Exception
Finally
myFileStream.Close()
End Try
End Function
No exception is ever raised. When I serialize, I can check the file
and it contains data (which means that serialization is working).
However, when I deserialize in the other application, I get 0 objects.
A final observation: serialization & deserialization work fine when
done within the same application. It is only between applications
that I have the problem.
Help?
BTW I would be interested in using the SOAPFormatter but I can't find
it in VB.NET. I read about it online but don't see it available.
What do I need to do to make that available to me? (I would much
prefer human-readable output when I serialize)
Thanks,
Marc