[Mono-list] IsSubclassOf and Assembly.LoadFrom problem

Colin JN Breame colin at breame.net
Fri Jan 6 08:53:52 EST 2006


On Thursday 05 January 2006 01:47, Elliott Draper wrote:
>
> if (t.GetInterface(typeof(a.a).FullName)!=null) {
>

This seems to work, and you were right - IsSubclassOf does not return true for 
interfaces.  Thanks.

>
> Maybe someone else can comment on whether or not IsSubclassOf *should*
> be returning true for interfaces, but in the meantime I hope the above
> information should help you out.
>
> Let me know how you get on,
> -= El =-
>
> 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...
> >
> >Thanks,
> > -- Colin
> >
> >
> >a.cs:
> >namespace a {
> >  public interface a {
> >    string hello();
> >  }
> >}
> >
> >
> >b.cs:
> >namespace b {
> >  public class b : a.a {
> >    public string hello() {
> >      return "hello world";
> >    }
> >  }
> >}
> >
> >
> >main.cs:
> >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)); }
> >      }
> >    }
> >  }
> >}
> >
> >
> >build.sh:
> >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
> >_______________________________________________
> >Mono-list maillist  -  Mono-list at lists.ximian.com
> >http://lists.ximian.com/mailman/listinfo/mono-list

-- 
Colin JN Breame
Freelance IT Consulting
e: colin at breame.net
t: +44(0)207 2630931
m: 0793 147 0091
w: http://breame.net
j: colinbreame at jabber.org


More information about the Mono-list mailing list