System.Reflection.ConstructorInfo.Invoke Method

When implemented in a derived class, invokes the constructor reflected by this ConstructorInfo with the specified arguments, under the constraints of the specified Binder.

Syntax

public abstract object Invoke (BindingFlags invokeAttr, Binder binder, object[] parameters, System.Globalization.CultureInfo culture)

Parameters

binder
A Binder that defines a set of properties and enables the binding, coercion of argument types, and invocation of members using reflection. If binder is null, then Binder.DefaultBinding is used.
parameters
An array of type Object used to match the number, order and type of the parameters for this constructor, under the constraints of binder. If this constructor does not require parameters, pass an array with zero elements, 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.
culture
A System.Globalization.CultureInfo used to govern the coercion of types. If this is null, the System.Globalization.CultureInfo for the current thread is used.
invokeAttr
One of the BindingFlags values that specifies the type of binding.
binder
A Binder that defines a set of properties and enables the binding, coercion of argument types, and invocation of members using reflection. If binder is null, then Binder.DefaultBinding is used.
parameters
An array of type Object used to match the number, order and type of the parameters for this constructor, under the constraints of binder. If this constructor does not require parameters, pass an array with zero elements, 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.
culture
A System.Globalization.CultureInfo used to govern the coercion of types. If this is null, the System.Globalization.CultureInfo for the current thread is used.

Returns

An instance of the class associated with the constructor.

Exceptions

TypeReason
ArgumentExceptionThe types of the elements of parameters do not match the types of the parameters accepted by the constructor reflected by the current instance, under the constraints of binder.
MethodAccessExceptionThe caller does not have the required permissions.
System.Reflection.TargetInvocationExceptionThe constructor reflected by the current instance threw an exception.
System.Reflection.TargetParameterCountException parameters.Length does not equal the number of parameters required by the contract of the constructor reflected by the current instance.

Remarks

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 that the parameters are of the correct number, order and type.

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.

Note:

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

Note:

Starting with the net_v20sp1_long, this method can be used to access non-public members if the caller has been granted System.Security.Permissions.ReflectionPermission with the System.Security.Permissions.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_v35_long or later.

Permissions

TypeReason
System.Security.Permissions.ReflectionPermissionRequires permission to invoke non-public members of loaded assemblies. See System.Security.Permissions.ReflectionPermissionFlag.MemberAccess.

Requirements

Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0