Export (0) Print
Expand All

Activator.CreateComInstanceFrom Method (String, String, Byte[], AssemblyHashAlgorithm)

Creates an instance of the COM object whose name is specified, using the named assembly file and the default constructor.

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

public static ObjectHandle CreateComInstanceFrom (
	string assemblyName,
	string typeName,
	byte[] hashValue,
	AssemblyHashAlgorithm hashAlgorithm
)
public static ObjectHandle CreateComInstanceFrom (
	String assemblyName, 
	String typeName, 
	byte[] hashValue, 
	AssemblyHashAlgorithm hashAlgorithm
)
public static function CreateComInstanceFrom (
	assemblyName : String, 
	typeName : String, 
	hashValue : byte[], 
	hashAlgorithm : AssemblyHashAlgorithm
) : ObjectHandle
Not applicable.

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.

hashValue

The value of the computed hash code.

hashAlgorithm

The hash algorithm used for hashing files and generating the strong name.

Return Value

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

Exception typeCondition

ArgumentNullException

typeName or assemblyName is a null reference (Nothing in Visual Basic).

ArgumentException

assemblyName is the empty string ("").

PathTooLongException

An assembly or module was loaded twice with two different evidences, or the assembly name is longer than MAX_PATH characters.

FileNotFoundException

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

FileLoadException

assemblyName is found but cannot be loaded.

BadImageFormatException

assemblyName is not a valid assembly.

SecurityException

A code base that does not start with "file://" was specified without the required WebPermission.

TypeLoadException

An instance cannot be created through COM.

-or-

typename was not found in assemblyName.

MissingMethodException

No matching constructor was found.

MemberAccessException

An instance of an abstract class cannot be created.

-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.

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 , this method can be used to create nonpublic types if the caller has been granted ReflectionPermission with the ReflectionPermissionFlag.ReflectionEmit 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 . For more information, see The .NET Framework 3.5 Architecture.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1

Community Additions

ADD
Show:
© 2015 Microsoft