ReadXml() on typed dataset causes InvalidCastException

M

Mike

Using Microsoft Development Environment 2002 v7.0.9466. In a C# ASP .Net
project, we have some typed datasets defined. (inherit from
System.Data.DataSet)

We call the ReadXml method of our typed dataset to load an XML string into it.

I have found that when one particular element is in the XML only once, I get
an InvalidCastException. The error doesn't happen if the element isn't
present, and it doesn't happen if the element is present more than once.

Here is the element...
<ExcessBagFees>100</ExcessBagFees>

Here is the error...

Exception: System.InvalidCastException


Message: Specified cast is not valid.


Source: System.Data


at System.Data.DataColumnCollection.get_Item(String name, String
ns)


at System.Data.XmlDataLoader.InferSchema(XmlElement tree, Hashtable
tableAtoms, DataTable table)


at System.Data.XmlDataLoader.InferSchema(XmlElement tree, Hashtable
tableAtoms, DataTable table)


at System.Data.XmlDataLoader.InferSchema(XmlDocument xdoc, String[]
excludedNamespaces)


at System.Data.DataSet.ReadXml(XmlReader reader, XmlReadMode mode,
Boolean denyResolving)


at System.Data.DataSet.ReadXml(XmlReader reader, XmlReadMode mode)


at ... (our code)

We are passing XmlReadMode = InferSchema to ReadXml.

If I pass the exact same XML string to a standard ADO .Net DataSet (not
typed),
there is no error.
 
S

Scott M.

Perhaps it is the data within the element that is not conforming to the
typed DataSet's expectation of the data type. Have you tried passing that
element in, but with say, string data, rather than numeric data?
 

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