[Mono-list] IsSubclassOf and Assembly.LoadFrom problem

Colin JN Breame colin at breame.net
Wed Jan 4 20:18:53 EST 2006

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...

 -- Colin

namespace a {
  public interface a {
    string hello();

namespace b {
  public class b : a.a {
    public string hello() {
      return "hello world";

using System;
using System.Reflection;

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 (t.IsSubclassOf(typeof(a.a))) {
          Console.WriteLine("{0} is a subclass of {1}", t, typeof(a.a));
        } else {
          Console.WriteLine("{0} is not a subclass of {1}", t, typeof(a.a));

mcs -target:library -out:a.dll a.cs &&
mcs -target:library -out:b.dll -r:a.dll b.cs &&
mcs -out:test.exe -r:a.dll test.cs

More information about the Mono-list mailing list