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
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