473,386 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Reflection - IsSubclassOf

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
Nov 16 '05 #1
3 4719

Thomas,

See http://www.gotdotnet.com/team/clr/Lo...Isolation.aspx

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2
Hi Mattias,
See

http://www.gotdotnet.com/team/clr/Lo...Isolation.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
Nov 16 '05 #3
>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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Shahzad Atta | last post by:
Hi All, I need to find out the types of control (i-e Combo Box , List box etc.) contained in a container. I can get the Type class but this only tells whether it is a class or a interface and so...
2
by: ME | last post by:
It appears that IsSubclassOf does not work. In the following example, why does typeof(IDerived).IsSubclassOf(typeof(IRoot)); yeild False when the IDerived interface DOES in fact derive from...
3
by: Martin Hazell | last post by:
I have an abstract class, with some other classes inheriting from it in my namespace. What I am would like to know is: is there any way (using reflection) that I would be able to get a list of...
1
by: D. Bron | last post by:
Hello, Can anyone tell me why I'm getting the following exception: Method not found: Void Maple.Collections.Set.UnionAll(System.Collections.ICollection) I'm not using reflection, I'm not...
2
by: Dan | last post by:
hi newsgroup, i need server side validation of user entries. as i do have many fields, i would like to use reflection for checkinng the IsValid property of all the Validators. here is the...
9
by: Paguro Bernardo | last post by:
Hi all, I'm building a user control in c#. This control has a property which can contain an instance of a user defined class which has to be a subclass of an abstract class A. I'd like the user...
0
by: Rob | last post by:
Hello, I'm new to C# and have a question regarding factoring through reflection. I have a database filled with data represented by name and value pairs. Each name has a identically named...
4
by: Per Bolmstedt | last post by:
(This question has been asked previously in this group, but I don't think it was ever really properly answered.) I want to use reflection - preferably - to find all Web Forms in my web site that...
6
by: alexbf | last post by:
Hello, I would like to know if it's possible using reflection to loop through all "web references" of a given assembly and get the url as specified in the web.config (dynamic url behavior). ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.