Home > .net, c# > Type.GetType and referred assemblies

Type.GetType and referred assemblies

January 27th, 2009 fbis

There is a DLL called CommonAssembly. This contains a namespace called CommonNamespace. This namespace contains a class called CommonClass.

Another project adds a reference to CommonAssembly and wants to get the type of CommonClass using the method Type.GetType.

Additional Information:

// This statement won’t work.
Type.GetType(”CommonClass”);
 
// This will not work either
Type.GetType(”CommonNamespace.CommonClass);

Since CommonClass type is defined in a referred assembly, Type.GetType will not be able to get the required type.

Solution:

Type.GetType(”CommonNamespace.CommonClass, CommonAssembly”);

Anything that is given after the comma (”,”) is taken as the assembly name. This assembly is searched for the given type name.

If the required class is not encapsulated in any namespace, then omit the namespace name.

Type.GetType(”CommonClass, CommonAssembly”);

If this doesn’t work, then try giving the fully qualified name of the assembly.

Categories: .net, c# Tags:
Comments are closed.