Binary serializing of dataset in framework 2.0

G

Guest

I was eager to try the new binary serialization of dataset in version 2.0 of
the framework. The new serialization seems to be very fast comparede to the
"binary" serialization in framework 1.1. However I have a few problems
consering columns of the type Date:

Columns set to the value of Date.MinValue and Date.MaxValue get corruptede
depending on the what time zone my computer is set to:

1. When time zone is set to Greenwich Mean Time (GMT) everything works just
fine.
2. When time zone is set to something east of GMT for example GMT +1
(Denmark) coulms with the value Date.MinValue are corrupted during the
serialization and deserialization.
3. When time zone is set to something west of GMT for example GMT -6
(Central Time US) coulms with the value Date.MaxValue are corrupted during
the serialization and deserialization.

I also expirience problems with null valus:

Columns with null values will be set to Date.MinVaule after deserialization
when time time zone is east of GMT.

Is this a bug or am i doing something worg?

I use the code below to demostrate this behaviour:

'Create a dataset for test purpose
'--------------------------------------
Dim drNew As DataRow
Me.DatasetOriginal = New DataSet

Me.DatasetOriginal.Tables.Add("TEST")
Me.DatasetOriginal.Tables("TEST").Columns.Add("Id", GetType(Integer))
Me.DatasetOriginal.Tables("TEST").Columns.Add("Name", GetType(String))
Me.DatasetOriginal.Tables("TEST").Columns.Add("Date", GetType(Date))
Me.DatasetOriginal.Tables("TEST").Columns.Add("Number",
GetType(Integer))
Me.DatasetOriginal.Tables("TEST").Columns.Add("Bool",
GetType(Boolean))

drNew = Me.DatasetOriginal.Tables("TEST").NewRow()
drNew.Item("Id") = 1
drNew.Item("Name") = "My name"
drNew.Item("Date") = Date.MaxValue
drNew.Item("Number") = 13
drNew.Item("Bool") = True
Me.DatasetOriginal.Tables("TEST").Rows.Add(drNew)

drNew = Me.DatasetOriginal.Tables("TEST").NewRow()
drNew.Item("Id") = 2
drNew.Item("Date") = Date.MinValue
drNew.Item("Number") = 13
drNew.Item("Bool") = True
Me.DatasetOriginal.Tables("TEST").Rows.Add(drNew)

drNew = Me.DatasetOriginal.Tables("TEST").NewRow()
drNew.Item("Id") = 3
drNew.Item("Name") = "My name"
drNew.Item("Number") = 13
drNew.Item("Bool") = True
Me.DatasetOriginal.Tables("TEST").Rows.Add(drNew)

drNew = Me.DatasetOriginal.Tables("TEST").NewRow()
drNew.Item("Id") = 4
drNew.Item("Name") = "My name"
drNew.Item("Date") = Date.Now
drNew.Item("Bool") = True
Me.DatasetOriginal.Tables("TEST").Rows.Add(drNew)

drNew = Me.DatasetOriginal.Tables("TEST").NewRow()
drNew.Item("Id") = 5
drNew.Item("Name") = "My name"
drNew.Item("Date") = Date.Now
drNew.Item("Number") = 13
Me.DatasetOriginal.Tables("TEST").Rows.Add(drNew)

'Serialize dataset
'-------------------
Dim bin As New
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim Writer2 As New System.IO.StreamWriter("C:\DatasetSerialized.dat")

Try
DatasetOriginal.WriteXml("C:\Serialized.xml",
XmlWriteMode.WriteSchema)

DatasetOriginal.RemotingFormat = SerializationFormat.Binary
bin.Serialize(Writer2.BaseStream, DatasetOriginal)
Writer2.Close()
Writer2 = Nothing
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

'DeSerializer dataset
'-----------------------
Dim bin As New
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim Reader As New System.IO.StreamReader("C:\DatasetSerialized.dat")

Try
DatasetSerialized = New DataSet
DatasetSerialized.RemotingFormat = SerializationFormat.Binary
DatasetSerialized = bin.Deserialize(Reader.BaseStream)
Reader.Close()
Reader = Nothing

DatasetSerialized.WriteXml("C:\DeSerialized.xml",
XmlWriteMode.WriteSchema)

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
 
K

Kay-Christian Wessel

Have you tried to use SerializationFormat.XML to see if there is any
difference ?

You could serialize as XML and then use the new compression features to make
the XML smaller. It will reduce the size to 4 % of the original size. It's
very nice with resources. Only 40 milliseconds on a 1 mb Dataset using the
Deflate compression.

Best regards
Kay-Christian Wessel
 
G

Guest

I have now tried the to serialize to XML and it seems to work fine.

so it seems to me that this is a bug in the binary serialization.

Anders
 
K

Kay-Christian Wessel

It is a pity since the binary serialization produced 80 % smaller output
compared to the XML serialization, using less than 10 % of the resources.

You will report this bug to Microsoft ?

Best regards
Kay-Christian Wessel
 
G

Guest

I would like to report it as a bug, but I am not sure how to do that.

Was is the official place to submit a bug report?

Anders
 

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