468,301 Members | 1,477 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,301 developers. It's quick & easy.

Serialization problem with DataTable

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.BinaryForm atter

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
Jul 21 '05 #1
4 1858
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.

Jul 21 '05 #2
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.

Jul 21 '05 #3
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
"Tian Min Huang" <ti******@online.microsoft.com> wrote in message
news:Ir**************@cpmsftngxa06.phx.gbl...
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.

Jul 21 '05 #4
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/de...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.

Jul 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Orly Junior | last post: by
reply views Thread by Stephan Moeller | last post: by
4 posts views Thread by Brian Keating | last post: by
1 post views Thread by elziko | last post: by
4 posts views Thread by David K | last post: by
5 posts views Thread by Henry Jones | last post: by
reply views Thread by Igor | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.