GetType Method (String, Boolean)

Assembly.GetType Method (String, Boolean)

Gets the Type object with the specified name in the assembly instance and optionally throws an exception if the type is not found.

Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)

public virtual Type GetType (
	string name,
	bool throwOnError
public Type GetType (
	String name, 
	boolean throwOnError
public function GetType (
	name : String, 
	throwOnError : boolean
) : Type
Not applicable.



The full name of the type.


true to throw an exception if the type is not found; false to return a null reference (Nothing in Visual Basic).

Return Value

A Type object that represents the specified class.

Exception typeCondition


name is invalid.


The length of name exceeds 1024 characters.


name is a null reference (Nothing in Visual Basic).


throwOnError is true, and the type cannot be found.


name requires a dependent assembly that could not be found.


name requires a dependent assembly that was found but could not be loaded.


The current assembly was loaded into the reflection-only context, and name requires a dependent assembly that was not preloaded.


name requires a dependent assembly, but the file is not a valid assembly.


name requires a dependent assembly which was compiled for a version of the runtime later than the currently loaded version.

This method only searches the current assembly instance. The name parameter includes the namespace but not the assembly. To search other assemblies for a type, use the Type.GetType method overload, which can optionally include an assembly display name as part of the type name.


If the type has been forwarded to another assembly, it is still returned by this method. For information on type forwarding, see Type Forwarding in the Common Language Runtime.

The throwOnError parameter only affects what happens when the type is not found. It does not affect any other exceptions that might be thrown. In particular, if the type is found but cannot be loaded, TypeLoadException can be thrown even if throwOnError is false.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

© 2015 Microsoft