Get a Type by name with namespace

suggest change

To do this you need a reference to the assembly which contains the type. If you have another type available which you know is in the same assembly as the one you want you can do this:

typeof(KnownType).Assembly.GetType(typeName);

typeName is the name of the type you are looking for, including the namespace, and KnownType is a type you know is in the same assembly.

This searches assemblies already loaded in the current application domain:

Type t = null;
foreach (Assembly ass in AppDomain.CurrentDomain.GetAssemblies())
{
    if (ass.FullName.StartsWith("System."))
        continue;
    t = ass.GetType(typeName);
    if (t != null)
        break;
}

Notice the check to exclude scanning System namespace assemblies to speed up the search. If your type may actually be a CLR type, you will have to delete these two lines.

If you have the assembly-qualified type name, including the assembly, you can load it with

Type.GetType(fullyQualifiedName);

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents