Click here to Skip to main content
11,584,208 members (55,539 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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
0 OriginalGriff 430
1 Sergey Alexandrovich Kryukov 329
2 Dave Kreskowiak 240
3 Richard Deeming 220
4 virusstorm 194
0 OriginalGriff 1,663
1 Sergey Alexandrovich Kryukov 1,229
2 Abhinav S 701
3 Dave Kreskowiak 667
4 Suvendu Shekhar Giri 568


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2015
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