I'm seeing a different behavior when I'm checking subclasses (Abstract->deriv) for type when I use the "base" type that is referenced in the checker program compared to when I explicitly load the "base" type in the checker program.
So if I do this in my main Checker program which has base type referenced (baseType) in:
- Load the derivType as Assembly.ReflectionOnlyLoadFrom(Path_to_deriv_dll)->typeToLoad
- var baseType = typeof(abstract_class) //Assembly for abstract_class is referenced in
- typeToLoad.IsSubClassOf(baseType) yields False
However if I do this:
- Load the baseType as Assembly.ReflectionOnlyLoadFrom(Path_to_base_type_dll)->baseType
- Load the derivType as Assembly.ReflectionOnlyLoadFrom(Path_to_deriv_dll)->typeToLoad
- Check typeToLoad.IsSubClassOf开发者_如何学JAVA(baseType), it yields as True
Any thoughts are appreciated.
The reason for this in your case is that the type have different identities. When using LoadFrom
the assembly is loaded into the LoadFrom context and vs. the references which are loaded into the Load
context. Because the assemblies are loaded into different contexts the types in the assemblies have different identities.
Here are some links with some more info on the subject http://blogs.msdn.com/b/suzcook/archive/0001/01/01/57248.aspx http://blogs.msdn.com/b/suzcook/archive/2003/05/29/57143.aspx
Make sure that the version of the assembly being referenced in the first option is the same version as the assembly being loaded dynamically in the second option. Provided you're loading the same exact assembly in both cases (same version, etc), you should get the same answer.
If, however, you are referencing a different version of the assembly, you may get a different answer.
精彩评论