System.Activator.CreateComInstanceFrom Method

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.

Syntax

public static System.Runtime.Remoting.ObjectHandle CreateComInstanceFrom (string assemblyName, string typeName)

Parameters

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

Returns

A handle that must be unwrapped to access the newly created instance.

Remarks

Use the System.Runtime.Remoting.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 Activator.CreateComInstanceFrom(string, string) 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 System.Reflection.Assembly.LoadFrom(string) and Activator.CreateInstance(Type, System.Reflection.BindingFlags, System.Reflection.Binder, Object[], System.Globalization.CultureInfo) methods.

Note:

Starting with the net_v20sp1_long, this method can be used to create nonpublic types 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 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_v35_long or later.

Requirements

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