[Mono-list] Re: IsSubclassOf and Assembly.LoadFrom problem

Robert Jordan robertj at gmx.net
Thu Jan 5 08:17:08 EST 2006

Colin JN Breame wrote:
> I've come across this problem before but never solved it (even after searching 
> the internet for several hours!).  So I thought I'd ask here....
> I have two dlls:
> 	a.dll - contains interface a.a
> 	b.dll - contains class b.b that implements a.a
> A main program loads b.dll and tests each type in the assembly to find out if 
> it implements a.a.  This all works except the class b.b (that I know 
> implements a.a) says that it doesn't! e.g. IsSubclassOf returns false.
> I think that this might have something to do with AppDomains or some other 
> restriction of loading and using types from a dynamically loaded assembly.  
> I'm really stuck with this (got that banging my head against a brick wall 
> feeling...) so any help would be greatly appreciated.
> Below is a test setup if you're wondering what I mean...

This is by design. Have a look at the section "Return value"
of http://tinyurl.com/bpnjl

You have to use typeof(a.a).IsAssignableFrom () instead:

> namespace test {
>   public class test {
>     public static void Main() {
>       Assembly a = Assembly.LoadFrom("b.dll");
>       Type[] types = a.GetTypes();
>       foreach (Type t in types) {

           if (typeof(a.a).IsAssignableFrom(t))
               Console.WriteLine("{0} is a subclass of {1}", t, 
               Console.WriteLine("{0} is not a subclass of {1}", t, 

>       }
>     }
>   }
> }


More information about the Mono-list mailing list