This documentation is archived and is not being maintained.

AppDomain.CreateComInstanceFrom Method (String, String)

Creates a new instance of a specified COM type. Parameters specify the name of a file that contains an assembly containing the type and the name of the type.

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

public ObjectHandle CreateComInstanceFrom(
	string assemblyName,
	string typeName


Type: System.String
The name of a file containing an assembly that defines the requested type.
Type: System.String
The name of the requested type.

Return Value

Type: System.Runtime.Remoting.ObjectHandle
An object that is a wrapper for the new instance specified by typeName. The return value needs to be unwrapped to access the real object.


assemblyName or typeName is null.


The type cannot be loaded.


The operation is attempted on an unloaded application domain.


No public parameterless constructor was found.


assemblyName is not found.


typeName is an abstract class.


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 an empty string ("").


assemblyName is not a valid assembly.


An assembly or module was loaded twice with two different evidences.


The COM object that is being referred to is null.

Use this method to create objects remotely without having to load the type locally.

The return value must to be unwrapped to access the real object.

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

The following sample demonstrates

using System;
using System.Reflection;
using System.Runtime.InteropServices;

class MyComVisibleType {
   public MyComVisibleType() {
      Console.WriteLine("MyComVisibleType instantiated!");

class MyComNonVisibleType {
   public MyComNonVisibleType() {
      Console.WriteLine("MyComNonVisibleType instantiated!");

class Test {
   public static void Main() {
      CreateComInstance("MyComNonVisibleType");   // Fail!
      CreateComInstance("MyComVisibleType");      // OK!

   static void CreateComInstance(string typeName) {
      try {
         AppDomain currentDomain = AppDomain.CurrentDomain;
         string assemblyName = currentDomain.FriendlyName;
         currentDomain.CreateComInstanceFrom(assemblyName, typeName);
      } catch (Exception e) {

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.