Click or drag to resize
TypeGetType Method (String, FuncAssemblyName, Assembly, FuncAssembly, String, Boolean, Type, Boolean, Boolean)
Gets the type with the specified name, specifying whether to perform a case-sensitive search and whether to throw an exception if the type is not found, and optionally providing custom methods to resolve the assembly and the type.

Namespace: System
Assembly: mscorlib (in mscorlib.dll) Version: 4.0.0.0
Syntax
C#
public static Type GetType(
	string typeName,
	Func<AssemblyName, Assembly> assemblyResolver,
	Func<Assembly, string, bool, Type> typeResolver,
	bool throwOnError,
	bool ignoreCase
)

Parameters

typeName
Type: SystemString
The name of the type to get. If the typeResolver parameter is provided, the type name can be any string that typeResolver is capable of resolving. If the assemblyResolver parameter is provided or if standard type resolution is used, typeName must be an assembly-qualified name (see AssemblyQualifiedName), unless the type is in the currently executing assembly or in Mscorlib.dll, in which case it is sufficient to supply the type name qualified by its namespace.
assemblyResolver
Type: SystemFuncAssemblyName, Assembly
A method that locates and returns the assembly that is specified in typeName. The assembly name is passed to assemblyResolver as an AssemblyName object. If typeName does not contain the name of an assembly, assemblyResolver is not called. If assemblyResolver is not supplied, standard assembly resolution is performed. Caution   Do not pass methods from unknown or untrusted callers. Doing so could result in elevation of privilege for malicious code. Use only methods that you provide or that you are familiar with.
typeResolver
Type: SystemFuncAssembly, String, Boolean, Type
A method that locates and returns the type that is specified by typeName from the assembly that is returned by assemblyResolver or by standard assembly resolution. If no assembly is provided, the method can provide one. The method also takes a parameter that specifies whether to perform a case-insensitive search; the value of ignoreCase is passed to that parameter. Caution   Do not pass methods from unknown or untrusted callers.
throwOnError
Type: SystemBoolean
true to throw an exception if the type cannot be found; false to return null. Specifying false also suppresses some other exception conditions, but not all of them. See the Exceptions section.
ignoreCase
Type: SystemBoolean
true to perform a case-insensitive search for typeName, false to perform a case-sensitive search for typeName.

Return Value

Type: Type
The type with the specified name. If the type is not found, the throwOnError parameter specifies whether null is returned or an exception is thrown. In some cases, an exception is thrown regardless of the value of throwOnError. See the Exceptions section.
Exceptions
ExceptionCondition
ArgumentNullExceptiontypeName is null.
TargetInvocationExceptionA class initializer is invoked and throws an exception.
TypeLoadExceptionthrowOnError is true and the type is not found. -or-throwOnError is true and typeName contains invalid characters, such as an embedded tab.-or-throwOnError is true and typeName is an empty string.-or-throwOnError is true and typeName represents an array type with an invalid size. -or-typeName represents an array of TypedReference.
ArgumentExceptionAn error occurs when typeName is parsed into a type name and an assembly name (for example, when the simple type name includes an unescaped special character).-or-throwOnError is true and typeName contains invalid syntax (for example, "MyType[,*,]").-or- typeName represents a generic type that has a pointer type, a ByRef type, or Void as one of its type arguments.-or-typeName represents a generic type that has an incorrect number of type arguments.-or-typeName represents a generic type, and one of its type arguments does not satisfy the constraints for the corresponding type parameter.
FileNotFoundExceptionthrowOnError is true and the assembly or one of its dependencies was not found.
FileLoadExceptionThe assembly or one of its dependencies was found, but could not be loaded. -or-typeName contains an invalid assembly name.-or-typeName is a valid assembly name without a type name.
BadImageFormatExceptionThe assembly or one of its dependencies is not valid. -or-The assembly was compiled with a later version of the common language runtime than the version that is currently loaded.
See Also