CreateInstance Method (Type, Object[])
Collapse the table of content
Expand the table of content

Activator.CreateInstance Method (Type, Object[])

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Creates an instance of the specified type by using the constructor that best matches the specified parameters.

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

public static Object CreateInstance(
	Type type,
	params Object[] args


Type: System.Type
The type of object to create.
Type: System.Object []
An array of arguments that match in number, order, and type the parameters of the constructor to invoke. If args is an empty array or null, the constructor that takes no parameters (the default constructor) is invoked.

Return Value

Type: System.Object
A reference to the newly created object.


type is null.


type is not a RuntimeType.


type is an open generic type (that is, the ContainsGenericParameters property returns true).


Creation of Void and RuntimeArgumentHandle types, or arrays of those types, is not supported.


The constructor that best matches args has varargs arguments.


The constructor being called throws an exception.


The caller does not have permission to call this constructor.


Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism.


No matching public constructor was found.


type is a COM object but the class identifier used to obtain the type is invalid, or the identified class is not registered.


type is not a valid type.

The type to be created must be accessible. The constructor to be invoked must be accessible and must provide the most specific match with the specified argument list. If you are using DynamicMethod to create a dynamic method, you cannot invoke internal constructors, because the dynamic method is hosted in an anonymous module in a system-provided assembly.

Version Notes

Windows Phone

 For types that do not have constructors defined, the Activator.CreateInstance(Type, Object[]) method throws a MemberAccessException exception instead of a MissingMethodException exception.

If you pass a null object to Activator.CreateInstance(Type, Object[]) on Windows Phone, the method throws NullReferenceException instead of NotSupportedException.

The following code example demonstrates how to call the CreateInstance(Type, Object[]) method. This code example is part of a larger example provided for the Activator class.

// Create an instance of StringBuilder using the constructor that takes a 
// string.
o = Activator.CreateInstance(sbType, new object[]{"Hello, there."});

// Append a string to the StringBuilder object and display the StringBuilder,
// late bound.
   BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, 
   o, new object[] {" And hello again!"});
outputBlock.Text += o.ToString() + "\n";

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2017 Microsoft