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