Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'objType' is not defined... Actually, it is, so why is this happening?

As you seen in this picture below, for some reason my DirectCast wont except ANYTHING for the second argument. It says it requires a type, but, it won't take any object at all!

enter image description here

Thanks for any help! I'm using VB.net so all .net answers are acceptable :)

EDIT

Ok, so apparently I'm not giving it the right kind of type. Could somebody please clarify this? Assuming the type it needs to cast to is gridElement, what should I replace objType with?

like image 805
Freesnöw Avatar asked Jan 18 '26 20:01

Freesnöw


2 Answers

DirectCast requires an object prototype (i.e. just giving it the intended class name) rather than a System.Type descriptor object. To cast an object using a System.Type, you will want to utilize CTypeDynamic():

Return CTypeDynamic(createElementByIdAndLayer.MemberwiseClone(), objType)

The error is essentially telling you a class with the type name "objType" does not exist.

like image 73
lsuarez Avatar answered Jan 20 '26 12:01

lsuarez


Its expecting a "Type", not a "Type Object".

What is the return value of the function?

like image 39
StingyJack Avatar answered Jan 20 '26 11:01

StingyJack



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!