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.