Edit

Share via


Type.GetTypeFromProgID Method

Definition

Gets the type associated with the specified program identifier (ProgID).

Overloads

GetTypeFromProgID(String)

Gets the type associated with the specified program identifier (ProgID), returning null if an error is encountered while loading the Type.

GetTypeFromProgID(String, Boolean)

Gets the type associated with the specified program identifier (ProgID), specifying whether to throw an exception if an error occurs while loading the type.

GetTypeFromProgID(String, String)

Gets the type associated with the specified program identifier (progID) from the specified server, returning null if an error is encountered while loading the type.

GetTypeFromProgID(String, String, Boolean)

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

GetTypeFromProgID(String)

Source:
Type.cs
Source:
Type.cs
Source:
Type.cs

Gets the type associated with the specified program identifier (ProgID), returning null if an error is encountered while loading the Type.

C#
public static Type? GetTypeFromProgID(string progID);
C#
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static Type? GetTypeFromProgID(string progID);
C#
[System.Security.SecurityCritical]
public static Type GetTypeFromProgID(string progID);
C#
public static Type GetTypeFromProgID(string progID);

Parameters

progID
String

The ProgID of the type to get.

Returns

The type associated with the specified ProgID, if progID is a valid entry in the registry and a type is associated with it; otherwise, null.

Attributes

Exceptions

progID is null.

Remarks

This method is provided for COM support. ProgIDs are not used in the Microsoft .NET Framework because they have been superseded by the concept of namespace.

See also

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.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 Standard 2.0, 2.1

GetTypeFromProgID(String, Boolean)

Source:
Type.cs
Source:
Type.cs
Source:
Type.cs

Gets the type associated with the specified program identifier (ProgID), specifying whether to throw an exception if an error occurs while loading the type.

C#
public static Type? GetTypeFromProgID(string progID, bool throwOnError);
C#
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static Type? GetTypeFromProgID(string progID, bool throwOnError);
C#
[System.Security.SecurityCritical]
public static Type GetTypeFromProgID(string progID, bool throwOnError);
C#
public static Type GetTypeFromProgID(string progID, bool throwOnError);

Parameters

progID
String

The ProgID of the type to get.

throwOnError
Boolean

true to throw any exception that occurs.

-or-

false to ignore any exception that occurs.

Returns

The type associated with the specified program identifier (ProgID), if progID is a valid entry in the registry and a type is associated with it; otherwise, null.

Attributes

Exceptions

progID is null.

The specified ProgID is not registered.

Examples

The following example retrieves a type by passing a ProgID, specifying whether to throw an exception if the ProgID is invalid. The example then displays the ClassID related to the ProgID, along with any applicable exception message.

C#
using System;
class MainApp
{
    public static void Main()
    {
        try
        {
            // Use the ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
            string myString1 ="DIRECT.ddPalette.3";
            // Use a nonexistent ProgID WrongProgID.
            string myString2 ="WrongProgID";
            // Make a call to the method to get the type information of the given ProgID.
            Type myType1 =Type.GetTypeFromProgID(myString1,true);
            Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType1.GUID);
            // Throw an exception because the ProgID is invalid and the throwOnError
            // parameter is set to True.
            Type myType2 =Type.GetTypeFromProgID(myString2,true);
        }
        catch(Exception e)
        {
            Console.WriteLine("An exception occurred.");
            Console.WriteLine("Source: {0}", e.Source);
            Console.WriteLine("Message: {0}", e.Message);
        }
    }
}

Remarks

This method is provided for COM support. Program IDs are not used in Microsoft .NET Framework because they have been superseded by the concept of namespace.

See also

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.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 Standard 2.0, 2.1

GetTypeFromProgID(String, String)

Source:
Type.cs
Source:
Type.cs
Source:
Type.cs

Gets the type associated with the specified program identifier (progID) from the specified server, returning null if an error is encountered while loading the type.

C#
public static Type? GetTypeFromProgID(string progID, string? server);
C#
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static Type? GetTypeFromProgID(string progID, string? server);
C#
[System.Security.SecurityCritical]
public static Type GetTypeFromProgID(string progID, string server);
C#
public static Type GetTypeFromProgID(string progID, string server);

Parameters

progID
String

The progID of the type to get.

server
String

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

Returns

The type associated with the specified program identifier (progID), if progID is a valid entry in the registry and a type is associated with it; otherwise, null.

Attributes

Exceptions

progID is null.

Examples

The following example retrieves a type by passing a ProgID and server name. The example then displays the ClassID related to the ProgID, or throws an exception if the ProgID or the server name is invalid.

C#
using System;
class MainApp
{
    public static void Main()
    {
        try
        {
            // Use the ProgID localhost\HKEY_CLASSES_ROOT\DirControl.DirList.1.
            string theProgramID ="DirControl.DirList.1";
            // Use the server name localhost.
            string theServer="localhost";
            // Make a call to the method to get the type information for the given ProgID.
            Type myType =Type.GetTypeFromProgID(theProgramID,theServer);
            if(myType==null)
            {
                throw new Exception("Invalid ProgID or Server.");
            }
            Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType.GUID);
        }
        catch(Exception e)
        {
            Console.WriteLine("An exception occurred.");
            Console.WriteLine("Source: {0}" , e.Source);
            Console.WriteLine("Message: {0}" , e.Message);
        }		
    }
}

Remarks

This method is provided for COM support. Program IDs are not used in Microsoft .NET Framework because they have been superseded by the concept of namespace.

See also

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.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 Standard 2.0, 2.1

GetTypeFromProgID(String, String, Boolean)

Source:
Type.cs
Source:
Type.cs
Source:
Type.cs

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

C#
public static Type? GetTypeFromProgID(string progID, string? server, bool throwOnError);
C#
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static Type? GetTypeFromProgID(string progID, string? server, bool throwOnError);
C#
[System.Security.SecurityCritical]
public static Type GetTypeFromProgID(string progID, string server, bool throwOnError);
C#
public static Type GetTypeFromProgID(string progID, string server, bool throwOnError);

Parameters

progID
String

The progID of the Type to get.

server
String

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

throwOnError
Boolean

true to throw any exception that occurs.

-or-

false to ignore any exception that occurs.

Returns

The type associated with the specified program identifier (progID), if progID is a valid entry in the registry and a type is associated with it; otherwise, null.

Attributes

Exceptions

progID is null.

The specified progID is not registered.

Examples

The following example retrieves a type by passing a ProgID and server name. The example then displays the ClassID related to the ProgID, specifying whether to throw an exception if the ProgID or the server name is invalid.

C#

using System;
class MainApp
{
    public static void Main()
    {
        try
        {
            // Use server localhost.
            string theServer="localhost";
            // Use  ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
            string myString1 ="DirControl.DirList.1";
            // Use a wrong ProgID WrongProgID.
            string myString2 ="WrongProgID";
            // Make a call to the method to get the type information for the given ProgID.
            Type myType1 =Type.GetTypeFromProgID(myString1,theServer,true);
            Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType1.GUID);
            // Throw an exception because the ProgID is invalid and the throwOnError
            // parameter is set to True.
            Type myType2 =Type.GetTypeFromProgID(myString2, theServer, true);
        }
        catch(Exception e)
        {
            Console.WriteLine("An exception occurred. The ProgID is wrong.");
            Console.WriteLine("Source: {0}" , e.Source);
            Console.WriteLine("Message: {0}" , e.Message);
        }
    }
}

Remarks

This method is provided for COM support. Program IDs are not used in Microsoft .NET Framework because they have been superseded by the concept of namespace.

See also

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.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 Standard 2.0, 2.1