HighTechTalks DotNet Forums  

ReadXml() on typed dataset causes InvalidCastException

Dotnet Framework (ADO.net) microsoft.public.dotnet.framework.adonet


Discuss ReadXml() on typed dataset causes InvalidCastException in the Dotnet Framework (ADO.net) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Mike
 
Posts: n/a

Default ReadXml() on typed dataset causes InvalidCastException - 12-07-2007 , 09:40 AM






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.



Reply With Quote
  #2  
Old   
Scott M.
 
Posts: n/a

Default Re: ReadXml() on typed dataset causes InvalidCastException - 12-09-2007 , 08:10 AM






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?


"Mike" <Mike (AT) discussions (DOT) microsoft.com> wrote

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





Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.