473,498 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Casting using XmlSchemaSequence on web form VS inside C# class

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)
PBTablesComplexType.Particle;
Nov 12 '05 #1
1 1684
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"
"Pete" <pe**@bga.com> wrote in message
news:39**************************@posting.google.c om...
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)
PBTablesComplexType.Particle;

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1762
by: Angelos Karantzalis | last post by:
Hi guys, I'm trying to load a class instance dynamically, and then cast it to it's base type so I can use it in my app. More specifically, I'm dynamically instantiating a...
4
1839
by: Chris | last post by:
I created a control that derives from the System.Windows.Forms.Control namespace. I then created an interface to which this new control must adhere, so that I could require future controls to...
44
2159
by: Agoston Bejo | last post by:
What happens exactly when I do the following: struct A { int i; string j; A() {} }; void f(A& a) { cout << a.i << endl;
8
9427
by: Razak | last post by:
Hi, I have a class which basically do Impersonation in my web application. From MS KB sample:- ++++++++++++++++++++code starts Dim impersonationContext As...
2
2139
by: harvie wang | last post by:
Hi, I want to implement a common Form with special interface, such as MovePoint(double,double). I create a interface first: namespace ABC.Test { public Interface IMyWindowInterface { void...
3
2747
by: Tigger | last post by:
I have an object which could be compared to a DataTable/List which I am trying to genericify. I've spent about a day so far in refactoring and in the process gone through some hoops and hit some...
2
2463
by: NullQwerty | last post by:
Hey folks, So, I've got three enum types: enum enum1 enum enum2 enum enum3 And then I've got a function overloaded three times to accept each enum type: private void func(enum1 myenum){}
9
3450
by: Taras_96 | last post by:
Hi everyone, I was experimenting with static_cast and reinterpret cast #include <iostream> struct A1 { int a; }; struct A2 { double d; }; struct B : public A1, A2
4
3004
by: Wally Barnes | last post by:
Can someone help a poor C++ programmer that learned the language before there was a standard lib .. etc ? Basically I have two classes that look something like below: template <class T>...
0
7126
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7005
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5465
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4595
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3096
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3087
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1424
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
659
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.