Reflection - IsSubclassOf

T

thomas

Hi,

I have three assemblies. In Assembly1 I define an abstract
base class called MyBaseClass. In Assembly2 I derive a
class from this MyBaseClass. If I asked in the derived
class if this class is a sublass of MyBaseClass the
function IsSubclassOf returns true, so this works properly.

In the third assembly however, I don't get the right
result when I ask for the subclass. My code looks as
follows:

//using namespace of Assembly1 where the MyBaseClass is
//defined

Assembly a = Assembly.LoadFrom(FileNameOfAssembly2);
foreach(Type t in a.GetTypes())
{
//the type of my derived class appaers here properly
if(t.IsSubclassOf(typeof(MyBaseClass)))
{
//never reached
}
}

I really don't know what is going wrong. I also printed
out the guid which I get from t.BaseClass.GUID. This guid
is exactly the one from MyBaseClass, so that is perfectly
right. What is going wrong? It seems to me that the types
are never recognized properly. The same happens for
attributes. If I print out the names then I get the right
ones, but if I ask explicitely for the type and compare
the type afterwards, no function returns the proper
results.

Thomas
 
T

thomas

Hi Mattias,
http://www.gotdotnet.com/team/clr/LoadFromIsolation.aspx

Thanks for the link. Now I understand why it cannot work.
But what make me crazy is, that it works somehow for
Microsoft...

I have a simple registration tool. This tool has a static
reference to an assembly which defines a BaseClass. The
LoadFrom loads an assembly which includes a subclass of
the BaseClass. The registration tool tries to figure out
if the loaded class is actually a subclass of the base
class and if so it tries to read attributes and register
those values.

The very strange thing is, that when I use a compiled (by
ms) version of the base class assembly all the code works
(which is supposed not to work...). But if I compile this
assembly myself (I have the sources) then the registration
tool suddenly don't work anymore because of the described
problems.

Do you have any ideas?


Thomas
 
M

Mattias Sjögren

Do you have any ideas?

Is the full assembly name (including version and public key token if
any) the same in the Microsoft assembly and the one you compiled
yourself?



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top