views:

108

answers:

2
+2  Q: 

C# Type comparison

This has me pooped, is there any reason the following:

public abstract class aExtension
{
    public abstract bool LoadExtension(Constants c); // method required in inherit
    public abstract string AppliesToModule // property required in inherit
    {
        get;
    }
    public abstract string ExtensionName // property required in inherit
    {
        get;
    }
    public abstract string ExtensionDescription // property required in inherit
    {
        get;
    }
}

public class UK : aExtension
{
    public override bool LoadExtension(Constants c)
    {
        return true;
    }
    public override string AppliesToModule
    {
        get { return "string"; }
    }
    public override string ExtensionName
    {
        get { return "string"; }
    }
    public override string ExtensionDescription
    {
        get { return "string"; }
    }
}

would return false for the following expressions:

                bool a = t.IsAssignableFrom(aExtension));
                bool b = t.BaseType.IsAssignableFrom(aExtension));
                bool c = typeof(aExtension).IsAssignableFrom(t);
                bool d = typeof(aExtension).IsAssignableFrom(t.BaseType);
                bool e = typeof(aExtension).IsSubclassOf(t);
                bool f = typeof(aExtension).IsSubclassOf(t.BaseType);
                bool g = t.IsSubclassOf(typeof(aExtension));
                bool h = t.BaseType.IsSubclassOf(typeof(LBT.AdMeter.aExtension));
                bool i = t.BaseType.Equals(typeof(aExtension));
                bool j = typeof(aExtension).Equals(t.BaseType);

T is the reflected Type from the calss UK.

Stange thing is i do the exact same thing just on an external assembly in the same application and it works as expected...

+1  A: 

UK probably inherits aExtension from a different version of the assembly.

SLaks
only one version exists, that being the current debug compile.
Sean.C
I just double checked this by refreshing references, compile on both sets of code, then checking the GUID of the assemblies in the project file - all match; yet still this strnage compasrion behaviour.
Sean.C
@Sean.C: Are you loading the assemblies with Reflection? It is possible that you are loading two instances of the same assembly into memory if you are loading the assembly by the file name.
Matthew Whited
you have it, i think - but have not tested. What i'm doing is loadin 'plugins' from a disk location, then iterating it's types checking for the aPlugin inherit.. i THEN re-iterate in another module checking for the aExtension inherit on the same disk location...
Sean.C
Check whether `typeof(aExtension).Assembly.Equals(t.BaseType.Assembly)`
SLaks
The plugin was probably built against an earlier version.
SLaks
nope, this the same version i just checked this - but something is happening inbetween checking for the 'aPlugin' inhertance, and checking for the 'aExtension' inheratence. I can check for the existance of 'aExtension' on the first load of the assembly just fine - works as expected; but when i dispose then re-load the type some how is from a different version.
Sean.C
typeof(aExtension).Assembly.Equals(t.BaseType.Assembly) returns false in the current location of the code. When i check this on the first load it returns true...
Sean.C
Matthew, thanks for the spot - i would have never relaised that. Do you know of a way i can revert to the cached version from my inital load? or even remove the cahced version from memory?
Sean.C
A: 

Do you have a copy of the same assembly around? If the same assembly is loaded from a different location, the types are not compatible.

Are you loading assemblies by reflection only somewhere? I think I had issues with that.

Stefan Steinegger
unfortunatly not, as that would have been somehting i would have missed.
Sean.C
One in GAC, one loaded from local folder?
Stefan Steinegger
it appears that way, Matthew pointed this out - and i makes sence i should ahve noted i actually check for the existance of another abtract class from another module prior to checking for 'aExtension' - thus putting the file on the GAC..
Sean.C