Serialization problem with DataTable

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
 
T

Tian Min Huang

Hi David,

Thanks for your post. I reproduced the problem with your code, and I am
performing further research on this issue.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
T

Tian Min Huang

Hello David,

I discussed this issue with an expert on ADO .NET, we found that
custom-typed columns serialization is not curerntly supported by the .NET
Framework. The custom deserialization constructor and GetObjecData methods
wouldn't be called so you never get the member data in the output stream.
Instead, the type name (columnitem.ToString()) is written to the stream.
During deserialization, the type name is read back so you get the type
"System.String".

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
D

David K

What do you mean does not supported in the .NET Framework?
if I use a HashTable or array list it works great ( which both are .NET
framework classes)
if it is not supported it should be well documented - currently the
documentation said that this class implement ISerializable
which lead you to think it support custom type columns.
Since it is not the first time we encounter with such undocumented caveats I
want to emphasize the importance of documenting those caveats to increase
the efficient of developers using .NET framework

David
 
T

Tian Min Huang

Hello David,

Thanks a lot for your feedback. I consulted our Developer Team and the
DataColumn supports the base .NET Framework data types (as documented in
the MSDN article below) serialization/deserialization, while it treat other
class types as string.

DataColumn.DataType Property
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemdatadatacolumnclassdatatypetopic.asp

Please feel free to let me know if you have any concerns.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top