Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Creates an instance of the COM object whose name is specified.
CreateComInstanceFrom(String, String) |
Creates an instance of the COM object whose name is specified, using the named assembly file and the parameterless constructor. |
CreateComInstanceFrom(String, String, Byte[], AssemblyHashAlgorithm) |
Creates an instance of the COM object whose name is specified, using the named assembly file and the parameterless constructor. |
Creates an instance of the COM object whose name is specified, using the named assembly file and the parameterless constructor.
public:
static System::Runtime::Remoting::ObjectHandle ^ CreateComInstanceFrom(System::String ^ assemblyName, System::String ^ typeName);
public static System.Runtime.Remoting.ObjectHandle CreateComInstanceFrom(string assemblyName, string typeName);
static member CreateComInstanceFrom : string * string -> System.Runtime.Remoting.ObjectHandle
Public Shared Function CreateComInstanceFrom (assemblyName As String, typeName As String) As ObjectHandle
The name of a file that contains an assembly where the type named typeName
is sought.
The name of the type to create an instance of.
A handle that must be unwrapped to access the newly created object, or null
for Nullable<T> instances.
typeName
or assemblyName
is null
.
An instance cannot be created through COM.
-or-
typeName
was not found in assemblyName
.
No matching constructor was found.
assemblyName
is not found, or the module you are trying to load does not specify a file name extension.
Cannot create an instance of an abstract class.
-or-
This member was invoked with a late-binding mechanism.
The caller cannot provide activation attributes for an object that does not inherit from MarshalByRefObject.
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.
Note
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 .NET Framework 3.5 or later.
Product | Versions |
---|---|
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Creates an instance of the COM object whose name is specified, using the named assembly file and the parameterless constructor.
public:
static System::Runtime::Remoting::ObjectHandle ^ CreateComInstanceFrom(System::String ^ assemblyName, System::String ^ typeName, cli::array <System::Byte> ^ hashValue, System::Configuration::Assemblies::AssemblyHashAlgorithm hashAlgorithm);
public static System.Runtime.Remoting.ObjectHandle CreateComInstanceFrom(string assemblyName, string typeName, byte[] hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm);
static member CreateComInstanceFrom : string * string * byte[] * System.Configuration.Assemblies.AssemblyHashAlgorithm -> System.Runtime.Remoting.ObjectHandle
Public Shared Function CreateComInstanceFrom (assemblyName As String, typeName As String, hashValue As Byte(), hashAlgorithm As AssemblyHashAlgorithm) As ObjectHandle
The name of a file that contains an assembly where the type named typeName
is sought.
The name of the type to create an instance of.
The value of the computed hash code.
The hash algorithm used for hashing files and generating the strong name.
A handle that must be unwrapped to access the newly created object, or null
for Nullable<T> instances.
typeName
or assemblyName
is null
.
assemblyName
is the empty string ("").
An assembly or module was loaded twice with two different evidences.
-or-
assemblyName
is longer than the system-defined maximum length.
assemblyName
is not found, or the module you are trying to load does not specify a file name extension.
assemblyName
is found but cannot be loaded.
assemblyName
is not a valid assembly.
A code base that does not start with "file://" was specified without the required WebPermission
.
An instance cannot be created through COM.
-or-
typeName
was not found in assemblyName
.
No matching constructor was found.
An instance of an abstract class cannot be created.
-or-
This member was invoked with a late-binding mechanism.
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.
Note
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 .NET Framework 3.5 or later.
Product | Versions |
---|---|
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in