Export (0) Print
Expand All

Assembly.GetType Method (String, Boolean, Boolean)

Updated: July 2010

Gets the Type object with the specified name in the assembly instance, with the options of ignoring the case, and of throwing an exception if the type is not found.

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

public Type GetType(
	string name,
	bool throwOnError,
	bool ignoreCase
)

Parameters

name
Type: System.String

The full name of the type.

throwOnError
Type: System.Boolean

true to throw an exception if the type is not found; false to return null.

ignoreCase
Type: System.Boolean

true to ignore the case of the type name; otherwise, false.

Return Value

Type: System.Type
A Type object that represents the specified class.

Implements

_Assembly.GetType(String, Boolean, Boolean)

ExceptionCondition
ArgumentException

name is invalid.

-or-

The length of name exceeds 1024 characters.

ArgumentNullException

name is null.

TypeLoadException

throwOnError is true, and the type cannot be found.

FileNotFoundException

name requires a dependent assembly that could not be found.

FileLoadException

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

-or-

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

BadImageFormatException

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

-or-

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(String) method overload, which can optionally include an assembly display name as part of the type name.

NoteNote:

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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Date

History

Reason

July 2010

Removed obsolete permission.

Customer feedback.

Community Additions

ADD
Show:
© 2014 Microsoft