Export (0) Print
Expand All

Type.ReflectionOnlyGetType Method

Updated: July 2010

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. The type is loaded for reflection only, not for execution.

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

public static function ReflectionOnlyGetType(
	typeName : String, 
	throwIfNotFound : boolean, 
	ignoreCase : boolean
) : Type

Parameters

typeName
Type: System.String

The assembly-qualified name of the Type to get.

throwIfNotFound
Type: System.Boolean

true to throw a TypeLoadException if the type cannot be found; false to return a null reference (Nothing in Visual Basic) if the type cannot be found. Specifying false also suppresses some other exception conditions, but not all of them. See the Exceptions section.

ignoreCase
Type: System.Boolean

true to perform a case-insensitive search for typeName; false to perform a case-sensitive search for typeName.

Return Value

Type: System.Type
The type with the specified name, if found; otherwise, a null reference (Nothing in Visual Basic). If the type is not found, the throwIfNotFound parameter specifies whether a null reference (Nothing in Visual Basic) is returned or an exception is thrown. In some cases, an exception is thrown regardless of the value of throwIfNotFound. See the Exceptions section.

ExceptionCondition
ArgumentNullException

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

TargetInvocationException

A class initializer is invoked and throws an exception.

TypeLoadException

throwIfNotFound is true and the type is not found.

-or-

throwIfNotFound is true and typeName contains invalid characters, such as an embedded tab.

-or-

throwIfNotFound is true and typeName is an empty string.

-or-

throwIfNotFound is true and typeName represents an array type with an invalid size.

-or-

typeName represents an array of TypedReference.

ArgumentException

typeName does not include the assembly name.

-or-

throwIfNotFound 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.

FileNotFoundException

throwIfNotFound is true and the assembly or one of its dependencies was not found.

FileLoadException

The assembly or one of its dependencies was found, but could not be loaded.

BadImageFormatException

The 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.

If the assembly containing the type is not already loaded into the reflection-only context, using the ReflectionOnlyGetType method is equivalent to first loading the assembly for reflection only, using the ReflectionOnlyLoad method, and then loading the type by calling the assembly's Assembly.GetType method. For information about assembly-qualified names, see the Type.AssemblyQualifiedName property. For additional details on specifying type names, see the GetType(String, Boolean, Boolean) method overload.

If the assembly is already loaded for execution, another copy is loaded into the reflection-only context.

The throwIfNotFound parameter specifies what happens when the type is not found, and also suppresses certain other exception conditions, as described in the Exceptions section. Some exceptions are thrown regardless of the value of throwIfNotFound. For example, if the assembly is not valid, a BadImageFormatException is thrown even if throwIfNotFound is false.

For more information about using the reflection-only context, see How to: Load Assemblies into the Reflection-Only Context.

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

Date

History

Reason

July 2010

Corrected parameter name.

Content bug fix.

June 2010

Clarified that typeName must be assembly-qualified.

Customer feedback.

June 2010

Added missing exceptions.

Customer feedback.

June 2010

Clarified the behavior of throwIfNotFound.

Content bug fix.

Community Additions

ADD
Show:
© 2014 Microsoft