Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / November 2004

Tip: Looking for answers? Try searching our database.

How does is subclass of work?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mgbee - 17 Nov 2004 14:48 GMT
I have a base class BusinessObject and I derive TestObject from it
public class TestObject:BusinessObject ...
I then create an an instance from an asembly of TestObject which returns an
object,
object retval=assembly.CreateInstance("MyClassLibrary.TestObject",false);
BusinessObject bo=(BusinessObject)retval;
throws "Specified cast is not valid" exception.
if I query the retval.GetType().BaseType i get BusinessObject,
however if i say retval.IsSubclassOf(typeof(BusinessObject)) it returns false,
yet
retval.IsSubclassOf(retval.GetType().BaseType) returns true
yet both are the same type,
first Do i need to create an explicit cast from object, I shouldn't have to
I believe,
secondly this seems to be inconsistent behavior for IsSubclassOf.
any help is appreciated.
yuri - 19 Nov 2004 05:47 GMT
This could happen if different versions of the same assembly are loaded into
the same application domain.  Try the following:

Type t1 = retval.GetType().BaseType;
Type t2 = typeof(BusinessObject);

Then inspect in the debugger (or by any other means) t1.Assembly and
t2.Assembly:
   Do they have the same version?
   Are they loaded from the same location (Assembly.Location)?

Thanks,
Yuri

>I have a base class BusinessObject and I derive TestObject from it
> public class TestObject:BusinessObject ...
[quoted text clipped - 15 lines]
> secondly this seems to be inconsistent behavior for IsSubclassOf.
> any help is appreciated.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.