Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

ConstructorInfo.Invoke Method (Object[])

Invokes the constructor reflected by the instance that has the specified parameters, providing default values for the parameters not commonly used.

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)
public Object Invoke(
	Object[] parameters
)

Parameters

parameters
Type: System.Object[]

An array of values that matches the number, order and type (under the constraints of the default binder) of the parameters for this constructor. If this constructor takes no parameters, then use either an array with zero elements or null, as in Object[] parameters = new Object[0]. Any object in this array that is not explicitly initialized with a value will contain the default value for that object type. For reference-type elements, this value is null. For value-type elements, this value is 0, 0.0, or false, depending on the specific element type.

Return Value

Type: System.Object
An instance of the class associated with the constructor.
ExceptionCondition
MemberAccessException

The class is abstract.

-or-

The constructor is a class initializer.

MethodAccessException
NoteNote

In the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, MemberAccessException, instead.

The constructor is private or protected, and the caller lacks ReflectionPermissionFlag.MemberAccess.

ArgumentException

The parameters array does not contain values that match the types accepted by this constructor.

TargetInvocationException

The invoked constructor throws an exception.

TargetParameterCountException

An incorrect number of parameters was passed.

NotSupportedException

Creation of TypedReference, ArgIterator, and RuntimeArgumentHandle types is not supported.

SecurityException

The caller does not have the necessary code access permission.

The number, type, and order of elements in the parameters array should be identical to the number, type, and order of parameters for the constructor reflected by this instance. Before calling the constructor, Invoke ensures that the caller has access permission and verifies that the parameters are valid.

Access restrictions are ignored for fully trusted code. That is, private constructors, methods, fields, and properties can be accessed and invoked using reflection whenever the code is fully trusted.

NoteNote

To create an instance of a value type that has no instance constructors, use the CreateInstance method.

This method is a convenience method for the following overloaded version, using default values. This method cannot be overridden.

NoteNote

Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public members if the caller has been granted ReflectionPermission with the ReflectionPermissionFlag.RestrictedMemberAccess flag and if the grant set of the non-public members is restricted to the caller’s grant set, or a subset thereof. (See Security Considerations for Reflection.)

To use this functionality, your application should target the .NET Framework 3.5 or later.

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft. All rights reserved.