Type.GetTypeFromCLSID Method (Guid, String, Boolean)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the type associated with the specified class identifier (CLSID) from the specified server, specifying whether to throw an exception if an error occurs while loading the type.

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

static member GetTypeFromCLSID : 
        clsid:Guid *
        server:string *
        throwOnError:bool -> Type


Type: System.Guid

The CLSID of the type to get.

Type: System.String

The server from which to load the type. If the server name is null, this method automatically reverts to the local machine.

Type: System.Boolean

true to throw any exception that occurs.


false to ignore any exception that occurs.

Return Value

Type: System.Type

System.__ComObject regardless of whether the CLSID is valid.

The GetTypeFromCLSID method supports late-bound access to unmanaged COM objects from .NET Framework apps when you know the COM object's class identifier (CLSID). The class identifier for COM classes is defined in the HKEY_CLASSES_ROOT\CLSID key of the registry. You can retrieve the value of the IsCOMObject property to determine whether the type returned by this method is a COM object.


You can call the GetTypeFromProgID method for late-bound access to COM objects whose programmatic identifier (ProgID) you know.

Instantiating an unmanaged COM object from its CLSID is a two-step process:

  1. Get a Type object that represents the __ComObject that corresponds to the CLSID by calling the GetTypeFromCLSID method.

  2. Call the Activator.CreateInstance(Type) method to instantiate the COM object.

Exceptions such as OutOfMemoryException will be thrown when specifying true for throwOnError, but it will not fail for unregistered CLSIDs.

Notes to Callers:

This method is intended for use when working with COM objects, not with .NET Framework objects. All managed objects, including those that are visible to COM (that is, their ComVisibleAttribute attribute is true) have a GUID that is returned by theGUIDproperty. Although theGetTypeFromCLSIDmethod returns a Type object that corresponds to the GUID for a particular managed object, you can't use that Type object to create a type instance by calling the Activator.CreateInstance method, as the following example shows.

No code example is currently available or this language may not be supported.

Instead, the GetTypeFromCLSID should only be used to retrieve the GUID of an unmanaged COM object, and the resultingType object that is passed to the Activator.CreateInstancemethod must represent an unmanaged COM object.

The following example uses the CLSID of the Microsoft Word Application object to retrieve a COM type that represents the Microsoft Word application from a server named computer17.central.contoso.com. It then instantiates the type by calling the Activator.CreateInstance method, and closes it by calling the Application.Quit method. An exception is thrown if an error occurs while loading the type.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top