Export (0) Print
Expand All

Assembly.CreateInstance Method (String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

Locates the specified type from this assembly and creates an instance of it using the system activator, with optional case-sensitive search and having the specified culture, arguments, and binding and activation attributes.

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

public virtual Object CreateInstance(
	string typeName,
	bool ignoreCase,
	BindingFlags bindingAttr,
	Binder binder,
	Object[] args,
	CultureInfo culture,
	Object[] activationAttributes
)

Parameters

typeName
Type: System.String

The Type.FullName of the type to locate.

ignoreCase
Type: System.Boolean

true to ignore the case of the type name; otherwise, false.

bindingAttr
Type: System.Reflection.BindingFlags

A bitmask that affects the way in which the search is conducted. The value is a combination of bit flags from BindingFlags.

binder
Type: System.Reflection.Binder

An object that enables the binding, coercion of argument types, invocation of members, and retrieval of MemberInfo objects via reflection. If binder is null, the default binder is used.

args
Type: System.Object[]

An array that contains the arguments to be passed to the constructor. This array of arguments must match in number, order, and type the parameters of the constructor to be invoked. If the default constructor is desired, args must be an empty array or null.

culture
Type: System.Globalization.CultureInfo

An instance of CultureInfo used to govern the coercion of types. If this is null, the CultureInfo for the current thread is used. (This is necessary to convert a String that represents 1000 to a Double value, for example, since 1000 is represented differently by different cultures.)

activationAttributes
Type: System.Object[]

An array of one or more attributes that can participate in activation. Typically, an array that contains a single UrlAttribute object. The UrlAttribute specifies the URL that is required to activate a remote object.

Return Value

Type: System.Object
An instance of the specified type, or null if typeName is not found. The supplied arguments are used to resolve the type, and to bind the constructor that is used to create the instance.

Implements

_Assembly.CreateInstance(String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

ExceptionCondition
ArgumentException

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

-or-

The current assembly was loaded into the reflection-only context.

ArgumentNullException

typeName is null.

MissingMethodException

No matching constructor was found.

NotSupportedException

A non-empty activation attributes array is passed to a type that does not inherit from MarshalByRefObject.

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.

-or-

The current assembly was loaded into the reflection-only context, and typeName requires a dependent assembly that was not preloaded.

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.

The activationAttributes parameter is related to client-activated objects; see Client Activation.

.NET Framework

Supported in: 4.5.2, 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

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