次の方法で共有


Assembly.GetType Method (String, Boolean)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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)

Syntax

'Declaration
Public Overridable Function GetType ( _
    name As String, _
    throwOnError As Boolean _
) As Type
public virtual Type GetType(
    string name,
    bool throwOnError
)

Parameters

  • throwOnError
    Type: System.Boolean
    true to throw an exception if the type is not found; false to return nulla null reference (Nothing in Visual Basic).

Return Value

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

Exceptions

Exception Condition
ArgumentException

name is invalid.

-or-

The length of name exceeds 1024 characters.

ArgumentNullException

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

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.

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.

MemberAccessException

The method is invoked late-bound through mechanisms such as Type.InvokeMember.

Remarks

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.

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.

Platform Notes

Silverlight for Windows Phone Silverlight for Windows Phone

 GetType throws a TypeLoadException exception instead of an ArgumentException exception when name is nulla null reference (Nothing in Visual Basic). If name is an invalid name, GetType returns nulla null reference (Nothing in Visual Basic).

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.