Click here to Skip to main content
12,501,845 members (51,535 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
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?
Posted 23-Jan-13 1:01am
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

It's because AppInfo is a reference type. Have a look at this article for the full explanation http://visualbasic.about.com/od/learnvbnet/a/casting1_3.htm[^]
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160919.1 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100