all groups > dotnet xml > december 2003 >
You're in the

dotnet xml

group:

Casting using XmlSchemaSequence on web form VS inside C# class


Casting using XmlSchemaSequence on web form VS inside C# class pete NO[at]SPAM bga.com
12/30/2003 1:07:02 PM
dotnet xml:
I am reading a schema with two DataTables and loading into a dataset.
In my intial tests I was using a web form. Everything was running
great so I convert it over to a class. Now I am getting
"System.InvalidCastException: Specified cast is not valid". I have
checked to make sure the same name spaces are included, they seam to
be the same in both web form and class.

Thanks in advance for help you can give

Here is the code

//Load schema using XmlSchema's Read() method
ads_working = new DataSet("PB_TABLES");
XmlTextReader reader = new XmlTextReader(ls_schemaPath);
XmlSchema schema = XmlSchema.Read(reader,null);

// this level is the PB_TABLES root no work needed here
XmlSchemaElement PBTablesElem = (XmlSchemaElement)schema.Items[0];
XmlSchemaComplexType PBTablesComplexType =
(XmlSchemaComplexType)PBTablesElem.SchemaType;

// this line causes the errror
XmlSchemaSequence PBTablesSeq= (XmlSchemaSequence)
Re: Casting using XmlSchemaSequence on web form VS inside C# class Kathleen Dollard
12/31/2003 8:24:55 PM
Pete,

I would suspect this particular ComplexType's compositor is not a sequence.
Thus the cast to sequence is invalid. Try something like

? PBTablesComplexType.Particle.GetType.Name

In the command window after setting a break point on the line that's failing
to see what type you're really looking at.

--
Kathleen Dollard
Microsoft MVP
Author "Code Generation in Microsoft .NET"


[quoted text, click to view]

AddThis Social Bookmark Button