I don't think nUnit has any problem, but someting with your codes setup. Is
the IInstrumentatio nAdministrator 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
IInstrumentatio nAdministrator 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.ex e ad if that one included the
interface definition .cs file then when you say
typeof(IInstrum entationAdminis trator) then the module of that type is going
to be myExecutable.ex e, 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(IInstrum entAdministrato r) 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 )
{
// typeLoadExcepti on.Types can generate null values.
if (typeInAssembly != null && !typeInAssembly .IsAbstract)
{
foreach (Type interfaceType in typeInAssembly. GetInterfaces() )
{
//TODO: Whats wrong with this: if (interfaceType ==
typeof(IInstrum entAdministrato r) ???
if (interfaceType. Name == typeof(IInstrum entAdministrato r).Name)
{
typesWithInterf ace.Add(typeInA ssembly);
}
}
}
}
Regards
/Niklas