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

Activator.CreateInstance Method (Type)

.NET Framework 1.1

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

[Visual Basic]
Overloads Public Shared Function CreateInstance( _
   ByVal type As Type _
) As Object
[C#]
public static object CreateInstance(
 Type type
);
[C++]
public: static Object* CreateInstance(
 Type* type
);
[JScript]
public static function CreateInstance(
   type : Type
) : Object;

Parameters

type
The type of object to create.

Return Value

A reference to the newly created object.

Exceptions

Exception Type Condition
ArgumentNullException type is a null reference (Nothing in Visual Basic).
ArgumentException type is not a RuntimeType.
NotSupportedException type cannot be a TypeBuilder.

-or-

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

TargetInvocationException The constructor being called throws an exception.
MethodAccessException The caller does not have permission to call this constructor.
MemberAccessException Cannot create an instance of an abstract class or this member was invoked with a late-binding mechanism.
InvalidComObjectException COM type was not obtained through GetTypeFromProgID or GetTypeFromCLSID.
MissingMethodException No matching public constructor was found.
COMException type is a COM object but the class identifier used to obtain the type is invalid, or the identified class is not registered.
TypeLoadException type is not a valid type.

Remarks

The constructor to be invoked must be accessible.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

.NET Framework Security: 

  • SecurityPermission for the ability to call unmanaged code when creating an instance of a delegate. Associated enumeration: SecurityPermissionFlag/UnmanagedCode
  • ReflectionPermission for the ability to invoke operations on all type members. Associated enumeration: ReflectionPermissionFlag/MemberAccess

See Also

Activator Class | Activator Members | System Namespace | Activator.CreateInstance Overload List

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.