Why doesn't Type.GetType () and Assembly.GetType () work?

I am trying to find a type at runtime from an assembly list; my code looks something like this:

foreach (Assembly assembly in assembliesToSearch)
{
    Type t = assembly.GetType(assemblyName);
    if (t != null)
    {
        return t;
    }
}

and the problem I have is that t always displays as null. Playing with a debugger and an intermediate window in VS2010, I noticed the following when I set a breakpoint inside the loop:

Type.GetType(typeof(MyNamespace.MyClass).AssemblyQualifiedName)

works fine but

assembly.GetType(typeof(MyNamespace.MyClass).AssemblyQualifiedName)

no (when the assembly is the assembly that I know contains the class I'm looking for - in the debugger I can put the clock on assembly.GetTypes (), go to the class I'm trying to create, and call assembly.GetType ("MyNamespace.MyClass , MyNamespace ")).

Does anyone know why searching for all assemblies using Type.GetType () works, but the search in the assembly that I know contains a type using assembly.GetType () not?

+5
1

MSDN Type.GetType() , Assembly.GetType() . .

typeof(MyNamespace.MyClass).AssemblyQualifiedName (- MyNamespace.MyClass, MyAssembly, Version=1.0.0.0, Culture=neutral), Assembly.GetType(), MyNamespace.MyClass.

, , , , Assembly.GetType(), , , . , null. Type.GetType(), , , , .


- :

, , , , Assembly.GetType() . Type.GetType(), , , , , , .

+9

All Articles