This documentation is archived and is not being maintained.

Type.GetType Method (String, Boolean)

.NET Framework 1.1

Gets the Type with the specified name, performing a case-sensitive search and specifying whether to throw an exception if an error occurs while loading the Type.

[Visual Basic]
Overloads Public Shared Function GetType( _
   ByVal typeName As String, _
   ByVal throwOnError As Boolean _
) As Type
public static Type GetType(
 string typeName,
 bool throwOnError
public: static Type* GetType(
 String* typeName,
 bool throwOnError
public static function GetType(
   typeName : String,
 throwOnError : Boolean
) : Type;


The name of the Type to get.
true to throw any exception that occurs.


false to ignore any exception that occurs.

Return Value

The Type with the specified name, if found; otherwise, a null reference (Nothing in Visual Basic).


Exception Type Condition
ArgumentNullException typeName is a null reference (Nothing in Visual Basic).
TargetInvocationException A class initializer is invoked and throws an exception.
TypeLoadException throwOnError is true and an error is encountered while loading the Type.


GetType only works on assemblies loaded from disk. If you call GetType to look up a type defined in a dynamic assembly defined using the System.Reflection.Emit services, you might get inconsistent behavior. The behavior depends on whether the dynamic assembly is persistent, that is, created using the RunAndSave or Save access modes of the System.Reflection.Emit.AssemblyBuilderAccess enumeration. If the dynamic assembly is persistent and has been written to disk before GetType is called, the loader finds the saved assembly on disk, loads that assembly, and retrieves the type from that assembly. If the assembly has not been saved to disk when GetType is called, the method returns a null reference (Nothing in Visual Basic). GetType does not understand transient dynamic assemblies; therefore, calling GetType to retrieve a type in a transient dynamic assembly returns a null reference (Nothing).

To use GetType on a dynamic module, subscribe to the AppDomain.AssemblyResolve event and call GetType before saving. Otherwise, you will get two copies of the assembly in memory.

If the requested type is non-public and the caller does not have ReflectionPermission to reflect non-public objects outside the current assembly, this method returns a null reference (Nothing).

The following table shows what members of a base class are returned by the Get methods when reflecting on a type.

Member Type Static Non-Static
Constructor No No
Field No Yes. A field is always hide-by-name-and-signature.
Event Not applicable The common type system rule is that the inheritance is the same as that of the methods that implement the property. Reflection treats properties as hide-by-name-and-signature. See note 2 below.
Method No Yes. A method (both virtual and non-virtual) can be hide-by-name or hide-by-name-and-signature.
Nested Type No No
Property Not applicable The common type system rule is that the inheritance is the same as that of the methods that implement the property. Reflection treats properties as hide-by-name-and-signature. See note 2 below.
  1. Hide-by-name-and-signature considers all of the parts of the signature, including custom modifiers, return types, parameter types, sentinels, and unmanaged calling conventions. This is a binary comparison.
  2. For reflection, properties and events are hide-by-name-and-signature. If you have a property with both a get and a set accessor in the base class, but the derived class has only a get accessor, the derived class property hides the base class property, and you will not be able to access the setter on the base class.
  3. Custom attributes are not part of the common type system.

Arrays or COM types are not searched for unless they have already been loaded into the table of available classes.

typeName can be a simple type name, a type name that includes a namespace, or a complex name that includes an assembly name specification.

If typeName includes only the name of the Type, this method searches in the calling object's assembly, then in the mscorlib.dll assembly. If typeName is fully qualified with the partial or complete assembly name, this method searches in the specified assembly.

AssemblyQualifiedName can return a fully qualified type name including nested types and the assembly name. All compilers that support the common language runtime will emit the simple name of a nested class, and reflection constructs a mangled name when queried, in accordance with the following conventions.

Delimiter Meaning
Backslash (\) Escape character.
Comma (,) Precedes the Assembly name.
Plus sign (+) Precedes a nested class.
Period (.) Denotes namespace identifiers.

For example, the fully qualified name for a class might look like this:


If the namespace were TopNamespace.Sub+Namespace, then the string would have to precede the plus sign (+) with an escape character (\) to prevent it from being interpreted as a nesting separator. Reflection emits this string as follows:


A "++" becomes "\+\+", and a "\" becomes "\\".

This qualified name can be persisted and later used to load the Type. To search for and load a Type, use GetType either with the type name only or with the assembly qualified type name. GetType with the type name only will look for the Type in the caller's assembly and then in the System assembly. GetType with the assembly qualified type name will look for the Type in any assembly.

Type names may include trailing characters that denote additional information about the type, such as whether the type is a reference type, a pointer type or an array type. To retrieve the type name without these trailing characters, use t.GetElementType().ToString(), where t is the type.

Spaces are relevant in all type name components except the assembly name. In the assembly name, spaces before the ',' separator are relevant, but spaces after the ',' separator are ignored.

The following table shows the syntax you use with GetType for various types.

To Get Use
An unmanaged pointer to MyType Type.GetType("MyType*")
An unmanaged pointer to a pointer to MyType Type.GetType("MyType**")
A managed pointer or reference to MyType Type.GetType("MyType&"). Note that unlike pointers, references are limited to one level.
A parent class and a nested class Type.GetType("MyParentClass+MyNestedClass")
A one-dimensional array with a lower bound of 0 Type.GetType("MyArray[]")
A one-dimensional array with an unknown lower bound Type.GetType("MyArray[*]")
An n-dimensional array A comma (,) inside the brackets a total of n-1 times. For example, System.Object[,,] represents a three-dimensional Object array.
A two-dimensional array's array Type.GetType("MyArray[][]")
A rectangular two-dimensional array with unknown lower bounds Type.GetType("MyArray[*,*]") or Type.GetType("MyArray[,]")


[Visual Basic, C#, C++] The following example retrieves the type of System.Int32 and uses that type object to display the FullName property of System.Int32. If a type object refers to an assembly that does not exist, this example throws an exception.

[Visual Basic] 
Imports System
Namespace MyTypeNameSpace
    Class MyClass1
        Public Shared Sub Main()
                ' Get the type of the specified class.
                Dim myType1 As Type = Type.GetType("System.Int32")
                Console.WriteLine("The full name is {0}.", myType1.FullName)
                ' Since NoneSuch does not exist in this assembly, GetType throws a TypeLoadException.
                Dim myType2 As Type = Type.GetType("NoneSuch", True)
                Console.WriteLine("The full name is {0}.", myType2.FullName)
            Catch e As TypeLoadException
            Catch e As Exception
            End Try
        End Sub 'Main
    End Class 'MyClass1
End Namespace 'MyTypeNameSpace

using System;
namespace MyTypeNameSpace
    class MyClass
        public static void Main(string[] arg)
                // Get the type of a specified class.
                Type myType1 = Type.GetType("System.Int32");
                Console.WriteLine("The full name is {0}.", myType1.FullName);
                // Since NoneSuch does not exist in this assembly, GetType throws a TypeLoadException.
                Type myType2 = Type.GetType("NoneSuch", true);
                Console.WriteLine("The full name is {0}.", myType2.FullName);
            catch(TypeLoadException e)
            catch(Exception e)

#using <mscorlib.dll>

using namespace System;

int main() {
   try {
      // Get the type of a specified class.
      Type*  myType1 = Type::GetType(S"System.Int32");
      Console::WriteLine(S"The full name is {0}.", myType1->FullName);
      // Since NoneSuch does not exist in this assembly, GetType throws a TypeLoadException.
      Type*  myType2 = Type::GetType(S"NoneSuch", true);
      Console::WriteLine(S"The full name is {0}.", myType2->FullName);
   } catch (TypeLoadException* e) {
   } catch (Exception* e) {

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

.NET Framework Security: 

See Also

Type Class | Type Members | System Namespace | Type.GetType Overload List | String | TypeLoadException | ReflectionPermission | AssemblyQualifiedName | GetAssembly | GetType | AssemblyName | Specifying Fully Qualified Type Names