469,934 Members | 1,540 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Error Deserializing DataSet Schema When Enum Column Uses Default Value

I have a column in a data table that stores enum values and assigns a default
value:

Dim dc As New DataColumn("TestEnumField", GetType(DayOfWeek))
dc.DefaultValue = DayOfWeek.Thursday

When I try to serialize/deserialize dataset schema, I get the error below
during deserialization:

"System.ArgumentException: The DefaultValue for column TestEnumField is of
type System.DBNull, but the column is of type System.DayOfWeek."

I've tried reading/writing the XML using the dataset's built-in methods as
well as using the SOAP formatter, both with the same results.

When I look at the XML file that gets created during serialization, I can see
that the default value for the column is there. In the above case, it is
stored as an integer, 4. So, it's not DBNull but maybe there's some problem
during the deserialization process converting 4 into DayOfWeek type?

Is this a bug or am I doing something wrong?

Thanks.
Mar 9 '06 #1
9 2658
Peter,

We cannot see if you do something wrong. How do you do the serializing. Is
it like this sample on our website?

http://www.vb-tips.com/default.aspx?...a-c891846eaf0b

Cor
"PeterWellington" <u19491@uwe> schreef in bericht news:5cfc2e14640cd@uwe...
I have a column in a data table that stores enum values and assigns a
default
value:

Dim dc As New DataColumn("TestEnumField", GetType(DayOfWeek))
dc.DefaultValue = DayOfWeek.Thursday

When I try to serialize/deserialize dataset schema, I get the error below
during deserialization:

"System.ArgumentException: The DefaultValue for column TestEnumField is of
type System.DBNull, but the column is of type System.DayOfWeek."

I've tried reading/writing the XML using the dataset's built-in methods as
well as using the SOAP formatter, both with the same results.

When I look at the XML file that gets created during serialization, I can
see
that the default value for the column is there. In the above case, it is
stored as an integer, 4. So, it's not DBNull but maybe there's some
problem
during the deserialization process converting 4 into DayOfWeek type?

Is this a bug or am I doing something wrong?

Thanks.

Mar 9 '06 #2
Cor Ligthert [MVP] wrote:
Peter,

We cannot see if you do something wrong. How do you do the serializing. Is
it like this sample on our website?

http://www.vb-tips.com/default.aspx?...a-c891846eaf0b

Cor
I have a column in a data table that stores enum values and assigns a
default

[quoted text clipped - 22 lines]

Thanks.


Yes, I've tried serializing/deserializing just as in the link you provided.
I'm pretty certain that's all correct in my code. For example, everything
serializes/deserializes error-free if I just take out the line of code where
I'm setting the default value for the DataColumn (i.e. commenting out "dc.
DefaultValue = DayOfWeek.Thursday").
Mar 9 '06 #3
Peter,

This code did run for me withouth any problem

\\\\
Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add("TestEnumField", GetType(DayOfWeek))
dt.LoadDataRow(New Object() {DayOfWeek.Thursday}, True)
Dim sw As New System.IO.StringWriter
ds.WriteXml(sw)
Dim mystring As String = sw.ToString
///

I hope this helps,

Cor
"PeterWellington" <u19491@uwe> schreef in bericht news:5cfc2e14640cd@uwe...
I have a column in a data table that stores enum values and assigns a
default
value:

Dim dc As New DataColumn("TestEnumField", GetType(DayOfWeek))
dc.DefaultValue = DayOfWeek.Thursday

When I try to serialize/deserialize dataset schema, I get the error below
during deserialization:

"System.ArgumentException: The DefaultValue for column TestEnumField is of
type System.DBNull, but the column is of type System.DayOfWeek."

I've tried reading/writing the XML using the dataset's built-in methods as
well as using the SOAP formatter, both with the same results.

When I look at the XML file that gets created during serialization, I can
see
that the default value for the column is there. In the above case, it is
stored as an integer, 4. So, it's not DBNull but maybe there's some
problem
during the deserialization process converting 4 into DayOfWeek type?

Is this a bug or am I doing something wrong?

Thanks.

Mar 9 '06 #4
Cor Ligthert [MVP] wrote:
Peter,

This code did run for me withouth any problem

\\\\
Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add("TestEnumField", GetType(DayOfWeek))
dt.LoadDataRow(New Object() {DayOfWeek.Thursday}, True)
Dim sw As New System.IO.StringWriter
ds.WriteXml(sw)
Dim mystring As String = sw.ToString
///

I hope this helps,

Cor
I have a column in a data table that stores enum values and assigns a
default

[quoted text clipped - 22 lines]

Thanks.


The problem is not writing it to a stream or file or reading from the file,
per se. It's during deserialization when a dataset is created from the
schema that was written to the XML file during the serialization process.
For example:

originalDataSet.WriteXmlSchema(filePath)
Dim targetDataSet As New DataSet()
targetDataSet.ReadXmlSchema(filePath)

The exception occurs when the target dataset tries to read back the XML
schema. As I mentioned before, I could also use a SOAP formatter to
serialize/deserialize and I get the same error.

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...neral/200603/1
Mar 10 '06 #5
Peter,

This code shows Thursday in a datagridview

Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add("TestEnumField", GetType(DayOfWeek))
dt.LoadDataRow(New Object() {DayOfWeek.Thursday}, True)
Dim sw As New System.IO.StringWriter
ds.WriteXml(sw)
Dim mystring As String = sw.ToString
Dim sr As New System.IO.StringReader(mystring)
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''
Dim ds2 As New DataSet
ds2.ReadXml(sr)
DataGridView1.DataSource = ds.Tables(0)
///

I can write the schema as well in this proces, that does not change the
result, however.

I hope this helps,

Cor

"PeterWellington via DotNetMonster.com" <u19491@uwe> schreef in bericht
news:5d06f4f0b1087@uwe...
Cor Ligthert [MVP] wrote:
Peter,

This code did run for me withouth any problem

\\\\
Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add("TestEnumField", GetType(DayOfWeek))
dt.LoadDataRow(New Object() {DayOfWeek.Thursday}, True)
Dim sw As New System.IO.StringWriter
ds.WriteXml(sw)
Dim mystring As String = sw.ToString
///

I hope this helps,

Cor
I have a column in a data table that stores enum values and assigns a
default

[quoted text clipped - 22 lines]

Thanks.


The problem is not writing it to a stream or file or reading from the
file,
per se. It's during deserialization when a dataset is created from the
schema that was written to the XML file during the serialization process.
For example:

originalDataSet.WriteXmlSchema(filePath)
Dim targetDataSet As New DataSet()
targetDataSet.ReadXmlSchema(filePath)

The exception occurs when the target dataset tries to read back the XML
schema. As I mentioned before, I could also use a SOAP formatter to
serialize/deserialize and I get the same error.

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...neral/200603/1

Mar 10 '06 #6
The problem occurs when you set a default value for the column. Here's a
simplified version of my code:

Dim ds As New DataSet("dsTest")
Dim dt As New DataTable("dtTest")

Dim dc As New DataColumn("TestEnumField", GetType(DayOfWeek))
dc.DefaultValue = DayOfWeek.Thursday
dt.Columns.Add(dc)
ds.Tables.Add(dt)

ds.WriteXmlSchema("C:\Temp\ds.xml")
Dim targetDS As New DataSet
targetDS.ReadXmlSchema("C:\Temp\ds.xml")

I think you'll find an error as well if you run the above code.

Cor Ligthert [MVP] wrote:
Peter,

This code shows Thursday in a datagridview

Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add("TestEnumField", GetType(DayOfWeek))
dt.LoadDataRow(New Object() {DayOfWeek.Thursday}, True)
Dim sw As New System.IO.StringWriter
ds.WriteXml(sw)
Dim mystring As String = sw.ToString
Dim sr As New System.IO.StringReader(mystring)
''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''
Dim ds2 As New DataSet
ds2.ReadXml(sr)
DataGridView1.DataSource = ds.Tables(0)
///

I can write the schema as well in this proces, that does not change the
result, however.

I hope this helps,

Cor
Peter,

[quoted text clipped - 34 lines]
schema. As I mentioned before, I could also use a SOAP formatter to
serialize/deserialize and I get the same error.


--
Message posted via http://www.dotnetmonster.com
Mar 10 '06 #7
Peter,

You are right, even this won't work.

\\\
Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add("TestEnumField")
dt.Columns("TestEnumField").DataType = GetType(System.DayOfWeek)
dt.Columns(0).DefaultValue = DayOfWeek.Thursday
dt.Rows.Add(dt.NewRow)
ds.WriteXml("C:\test.xml", XmlWriteMode.WriteSchema)
Dim ds2 As New DataSet
ds2.ReadXml("C:\test.xml")
DataGridView1.DataSource = ds2.Tables(0)
///
He is converting the default value to 4 and won't than except it anymore.

I assume that it is a bug, I will see if (how) I can report this.

Cor
"PeterWellington via DotNetMonster.com" <u19491@uwe> schreef in bericht
news:5d0927fcaa160@uwe...
The problem occurs when you set a default value for the column. Here's a
simplified version of my code:

Dim ds As New DataSet("dsTest")
Dim dt As New DataTable("dtTest")

Dim dc As New DataColumn("TestEnumField", GetType(DayOfWeek))
dc.DefaultValue = DayOfWeek.Thursday
dt.Columns.Add(dc)
ds.Tables.Add(dt)

ds.WriteXmlSchema("C:\Temp\ds.xml")
Dim targetDS As New DataSet
targetDS.ReadXmlSchema("C:\Temp\ds.xml")

I think you'll find an error as well if you run the above code.

Cor Ligthert [MVP] wrote:
Peter,

This code shows Thursday in a datagridview

Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add("TestEnumField", GetType(DayOfWeek))
dt.LoadDataRow(New Object() {DayOfWeek.Thursday}, True)
Dim sw As New System.IO.StringWriter
ds.WriteXml(sw)
Dim mystring As String = sw.ToString
Dim sr As New System.IO.StringReader(mystring)
'''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''
Dim ds2 As New DataSet
ds2.ReadXml(sr)
DataGridView1.DataSource = ds.Tables(0)
///

I can write the schema as well in this proces, that does not change the
result, however.

I hope this helps,

Cor
Peter,

[quoted text clipped - 34 lines]
schema. As I mentioned before, I could also use a SOAP formatter to
serialize/deserialize and I get the same error.


--
Message posted via http://www.dotnetmonster.com

Mar 10 '06 #8
Peter,

I have reported it as Bug

Cor
"Cor Ligthert [MVP]" <no************@planet.nl> schreef in bericht
news:uU**************@TK2MSFTNGP10.phx.gbl...
Peter,

You are right, even this won't work.

\\\
Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add("TestEnumField")
dt.Columns("TestEnumField").DataType = GetType(System.DayOfWeek)
dt.Columns(0).DefaultValue = DayOfWeek.Thursday
dt.Rows.Add(dt.NewRow)
ds.WriteXml("C:\test.xml", XmlWriteMode.WriteSchema)
Dim ds2 As New DataSet
ds2.ReadXml("C:\test.xml")
DataGridView1.DataSource = ds2.Tables(0)
///
He is converting the default value to 4 and won't than except it anymore.

I assume that it is a bug, I will see if (how) I can report this.

Cor
"PeterWellington via DotNetMonster.com" <u19491@uwe> schreef in bericht
news:5d0927fcaa160@uwe...
The problem occurs when you set a default value for the column. Here's a
simplified version of my code:

Dim ds As New DataSet("dsTest")
Dim dt As New DataTable("dtTest")

Dim dc As New DataColumn("TestEnumField", GetType(DayOfWeek))
dc.DefaultValue = DayOfWeek.Thursday
dt.Columns.Add(dc)
ds.Tables.Add(dt)

ds.WriteXmlSchema("C:\Temp\ds.xml")
Dim targetDS As New DataSet
targetDS.ReadXmlSchema("C:\Temp\ds.xml")

I think you'll find an error as well if you run the above code.

Cor Ligthert [MVP] wrote:
Peter,

This code shows Thursday in a datagridview

Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add("TestEnumField", GetType(DayOfWeek))
dt.LoadDataRow(New Object() {DayOfWeek.Thursday}, True)
Dim sw As New System.IO.StringWriter
ds.WriteXml(sw)
Dim mystring As String = sw.ToString
Dim sr As New System.IO.StringReader(mystring)
''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''
Dim ds2 As New DataSet
ds2.ReadXml(sr)
DataGridView1.DataSource = ds.Tables(0)
///

I can write the schema as well in this proces, that does not change the
result, however.

I hope this helps,

Cor

>Peter,
>
[quoted text clipped - 34 lines]
schema. As I mentioned before, I could also use a SOAP formatter to
serialize/deserialize and I get the same error.


--
Message posted via http://www.dotnetmonster.com


Mar 10 '06 #9
Thanks for looking into this. I appreciate it.

Cor Ligthert [MVP] wrote:
Peter,

I have reported it as Bug

Cor
Peter,

[quoted text clipped - 67 lines]
> schema. As I mentioned before, I could also use a SOAP formatter to
> serialize/deserialize and I get the same error.


--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...neral/200603/1
Mar 11 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Usha Vas | last post: by
6 posts views Thread by Peter Frost | last post: by
4 posts views Thread by ron | last post: by
1 post views Thread by Matt Tinson | last post: by
3 posts views Thread by Jason L James | last post: by
1 post views Thread by archana | last post: by
reply views Thread by =?Utf-8?B?dm96ZWxkcg==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.