Export (0) Print
Expand All

Activator.CreateComInstanceFrom Method (String, String)

Creates an instance of the COM object whose name is specified, using the named assembly file and the constructor that best matches the specified parameters.

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

public static ObjectHandle CreateComInstanceFrom(
	string assemblyName,
	string typeName
)

Parameters

assemblyName
Type: System.String

The name of a file that contains an assembly where the type named typeName is sought.

typeName
Type: System.String

The name of the preferred type.

Return Value

Type: System.Runtime.Remoting.ObjectHandle
A handle that must be unwrapped to access the newly created instance.

ExceptionCondition
ArgumentNullException

typeName or assemblyName is null.

TypeLoadException

An instance cannot be created through COM.

-or-

typename was not found in assemblyName.

MissingMethodException

No matching constructor was found.

FileNotFoundException

assemblyName is not found, or the module you are trying to load does not specify a file name extension.

MemberAccessException

Cannot create an instance of an abstract class.

-or-

This member was invoked with a late-binding mechanism.

NotSupportedException

The caller cannot provide activation attributes for an object that does not inherit from MarshalByRefObject.

ArgumentException

assemblyName is the empty string ("").

Use the ObjectHandle.Unwrap method to unwrap the return value.

A System.Runtime.InteropServices.ComVisibleAttribute attribute with a value of true must be applied either explicitly or by default to the COM type so the CreateComInstanceFrom method can create an instance of that type; otherwise, TypeLoadException is thrown.

For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the Assembly.LoadFrom and CreateInstance methods.

NoteNote

Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to create nonpublic types if the caller has been granted ReflectionPermission with the ReflectionPermissionFlag.RestrictedMemberAccess flag and if the grant set of the assembly that contains the nonpublic types is restricted to the caller’s grant set or to 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.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