This documentation is archived and is not being maintained.

Activator.CreateComInstanceFrom Method (String, String)

.NET Framework 1.1

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.

[Visual Basic]
Overloads Public Shared Function CreateComInstanceFrom( _
   ByVal assemblyName As String, _
   ByVal typeName As String _
) As ObjectHandle
[C#]
public static ObjectHandle CreateComInstanceFrom(
 string assemblyName,
 string typeName
);
[C++]
public: static ObjectHandle* CreateComInstanceFrom(
 String* assemblyName,
 String* typeName
);
[JScript]
public static function CreateComInstanceFrom(
   assemblyName : String,
 typeName : String
) : ObjectHandle;

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.

Return Value

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

Exceptions

Exception Type Condition
ArgumentNullException typeName is a null reference (Nothing in Visual Basic).
TypeLoadException An instance cannot be created through COM.
MissingMethodException No matching constructor was found.
TypeLoadException typename was not found in assemblyName.
MemberAccessException Cannot create an instance of an abstract class or this member was invoked with a late-binding mechanism.

Remarks

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.

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 Framework Security: 

  • ReflectionPermission for the ability to invoke operations on all type members. Associated enumeration: ReflectionPermissionFlag/MemberAccess

See Also

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

Show: