A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.

Element6

Well-known member
Joined
Feb 16, 2010
Messages
85
Programming Experience
5-10
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll

I am receiving this error; I know that it is throwing it because of a System.Reflection problem derived from an inheirt class. In psudeo code I have

ClassA
somePropA
somePropB
End class

ClassB
must inherit ClassA

somePropAB
somePropBB
End Class


I create an instance of ClassB

Dim instanceOfB as new ClassB

Then I use System.Reflection to retrieve the Properties.

Dim someProps() = instanceOfB.GetType.GetProperties()

The problem only occurs when I try to reference the ClassA property Info; I am Typing it correctly; so I think the error is wrong; unless VB.NET is somehow doing a temporary conversion which I doubt.

Anyone have any IDEAs what this might be? And how to solve it?

I have tried to CObj the type return as a part of the .GetValue Method that doesn't seem to work.

My problem is slightly complicated because I use the .GetValue Method to retrieve information; and all my properties are indexed.

The specific Inner Exception says the following :
"Exception has been thrown by the target of an invocation."

Does that specifically refer to the ClassB stating it cannot pass back the value because it is technically a different TYPE then ClassA? If that is true; then Inheritance is not working the way I thought it was supposed to.

In my understanding ClassB is the Type, and ClassA is just the type Reference.
 
Last edited:
Found the problem for the Type Cast; and it's good knowledge.

In my derived CLASSA I was returning an invalid type.

I had a TYPE Long as the property TYPE;

and instead of returning a LONG I was returning a different TYPE of a different CLASS.

This might be helpful for your problem.

Now I am getting a different problem because I am attempting to send indexed information that is not compliant with the Property Index.

Does anyone; off hand know if you send an ARRAY of INDEX objects if the property will attempt to order it? or Do I need to do that manually?
 

Latest posts

Back
Top