I don't think nUnit has any problem, but someting with your codes setup. Is
the IInstrumentationAdministrator interface defined in a single file that is
compiled separately into the assembly you loaded and referenced by the
executing code. If this is the case then when you are iterating through the
types from the loaded assembly you will get to a
IInstrumentationAdministrator type but its fully qualified name will include
the module it came from i.e. myAssembly1.dll, whereas you executing code is
in a different module i.e. myExecutable.exe ad if that one included the
interface definition .cs file then when you say
typeof(IInstrumentationAdministrator) then the module of that type is going
to be myExecutable.exe, hence when you compare the two types they are
considered to be different because their modules are different. The code
would work for the .Name comparison since that compares just the simple name
of the type which is not taking into account the module name.
This is just my guess, if you break in the debugger on the line where you
compare the types and it is failing, look at the module name and see if they
are different.
Mark.
--
http://www.markdawson.org http://themightycoder.spaces.live.com
"Niklas" wrote:
Hi
I found the problem...nUnit. In nUnit (interfaceType ==
typeof(IInstrumentAdministrator) this is false, but if I run the same code in
a Console application it is true.
Regards
/Niklas
"Niklas" wrote:
Hi
Look at the TODO in the code. The commented code do not work, but the code
below the commented one does. How do I do to compare Types?
foreach (Type typeInAssembly in typesInAssemply)
{
// typeLoadException.Types can generate null values.
if (typeInAssembly != null && !typeInAssembly.IsAbstract)
{
foreach (Type interfaceType in typeInAssembly.GetInterfaces())
{
//TODO: Whats wrong with this: if (interfaceType ==
typeof(IInstrumentAdministrator) ???
if (interfaceType.Name == typeof(IInstrumentAdministrator).Name)
{
typesWithInterface.Add(typeInAssembly);
}
}
}
}
Regards
/Niklas