Click here to Skip to main content
15,947,958 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello, this is Vikash Gohil.

I have a class in which I have the following constructor.

dim xyz as AppInfo

sub abc (byref Arg1 as object, byref Arg2 as Object)

xyz = DirectCast(Arg2, AppInfo)    

end sub

Above code is executed using reflection by passing 2 parameters

Param1 as type OracleTransaction
Param2 as type AppInfo

The above code gives error in DirectCast Statement as "Unable to Convert variable of type "AppInfo" to type "AppInfo""

why does it give error when the types are same?

It's because AppInfo is a reference type. Have a look at this article for the full explanation[^]
Share this answer
This shouldn't even be a problem as, apparently, the first thing you're doing is converting param2 to an AppInfo object. Why are you even specifying an Object type in the function header to begin with?? Just change it to AppInfo and be done with it, no conversion necessary.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900