共用方式為


Assembly.CreateInstance Method

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

Locates the specified type from this assembly and creates an instance of it using the system activator, using case-sensitive search.

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

Syntax

'Declaration
Public Function CreateInstance ( _
    typeName As String _
) As Object
public Object CreateInstance(
    string typeName
)

Parameters

Return Value

Type: System.Object
An instance of Object representing the type, with culture, arguments, binder, and activation attributes set to nulla null reference (Nothing in Visual Basic), and BindingFlags set to Public or Instance, or nulla null reference (Nothing in Visual Basic) if typeName is not found.

Exceptions

Exception Condition
ArgumentException

typeName is an empty string ("") or a string beginning with a null character.

ArgumentNullException

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

MissingMethodException

No matching constructor was found.

FileNotFoundException

typeName requires a dependent assembly that could not be found.

FileLoadException

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

BadImageFormatException

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

-or-

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

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.