D
David K
we are having a problem when trying to serilalize and deserialize DataTable
When replacing the container to be ListArray or HashTable everything works
fine
The code is very straight forward ( see below), however when comparing the
DataTable before and after the serialize, it is not the same
The DataTable after the serialization contains only the string of class type
( Vclass in this class) but not the class itself
Any idea ?
David
-----
Dim bfx As New Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim _streamx As New IO.MemoryStream
Dim vidSrc As New VClass(999, 1)
Dim dtSrc As New DataTable
dtSrc.Columns.Add("vid", GetType(VClass))
Dim newRow As DataRow = dtSrc.NewRow()
newRow("vid") = vidSrc
dtSrc.Rows.Add(newRow)
bfx.Serialize(_streamx, dtSrc)
_streamx.Position = 0
Dim dtDest As DataTable = bfx.Deserialize(_streamx)
Where VClass is as follows:
<Serializable()> Public Class VClass
Implements Runtime.Serialization.ISerializable
Protected m_id As Integer
Protected m_owner As Integer
'Serialization function.
Public Sub New()
MyBase.new()
m_id = -1
m_owner = 1
End Sub
Public Sub New(ByVal id As Integer, ByVal owner As Integer)
MyBase.new()
m_id = id
m_owner = owner
End Sub
'copy CTOr
Public Sub New(ByVal other As VClass)
MyBase.new()
m_id = other.m_id
m_owner = other.m_owner
End Sub
Protected Sub New(ByVal info As Runtime.Serialization.SerializationInfo,
ByVal context As Runtime.Serialization.StreamingContext)
m_id = CInt(info.GetValue("m_id", GetType(Integer)))
m_owner = CInt(info.GetValue("m_owner", GetType(Integer)))
End Sub 'New
Public Sub GetObjectData(ByVal info As
Runtime.Serialization.SerializationInfo, ByVal context As
Runtime.Serialization.StreamingContext) Implements
Runtime.Serialization.ISerializable.GetObjectData
info.AddValue("m_id", m_id)
info.AddValue("m_owner", m_owner)
End Sub 'GetObjectData
When replacing the container to be ListArray or HashTable everything works
fine
The code is very straight forward ( see below), however when comparing the
DataTable before and after the serialize, it is not the same
The DataTable after the serialization contains only the string of class type
( Vclass in this class) but not the class itself
Any idea ?
David
-----
Dim bfx As New Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim _streamx As New IO.MemoryStream
Dim vidSrc As New VClass(999, 1)
Dim dtSrc As New DataTable
dtSrc.Columns.Add("vid", GetType(VClass))
Dim newRow As DataRow = dtSrc.NewRow()
newRow("vid") = vidSrc
dtSrc.Rows.Add(newRow)
bfx.Serialize(_streamx, dtSrc)
_streamx.Position = 0
Dim dtDest As DataTable = bfx.Deserialize(_streamx)
Where VClass is as follows:
<Serializable()> Public Class VClass
Implements Runtime.Serialization.ISerializable
Protected m_id As Integer
Protected m_owner As Integer
'Serialization function.
Public Sub New()
MyBase.new()
m_id = -1
m_owner = 1
End Sub
Public Sub New(ByVal id As Integer, ByVal owner As Integer)
MyBase.new()
m_id = id
m_owner = owner
End Sub
'copy CTOr
Public Sub New(ByVal other As VClass)
MyBase.new()
m_id = other.m_id
m_owner = other.m_owner
End Sub
Protected Sub New(ByVal info As Runtime.Serialization.SerializationInfo,
ByVal context As Runtime.Serialization.StreamingContext)
m_id = CInt(info.GetValue("m_id", GetType(Integer)))
m_owner = CInt(info.GetValue("m_owner", GetType(Integer)))
End Sub 'New
Public Sub GetObjectData(ByVal info As
Runtime.Serialization.SerializationInfo, ByVal context As
Runtime.Serialization.StreamingContext) Implements
Runtime.Serialization.ISerializable.GetObjectData
info.AddValue("m_id", m_id)
info.AddValue("m_owner", m_owner)
End Sub 'GetObjectData