This documentation is archived and is not being maintained.

ProgIdAttribute Class

Allows the user to specify the ProgID of a class.

For a list of all members of this type, see ProgIdAttribute Members.


[Visual Basic]
NotInheritable Public Class ProgIdAttribute
   Inherits Attribute
public sealed class ProgIdAttribute : Attribute
public __gc __sealed class ProgIdAttribute : public Attribute
class ProgIdAttribute extends Attribute

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


You can apply this attribute to classes.

ProgIDs are automatically generated for a class by combining the namespace with the type name. This can produce an invalid ProgID however, as ProgIDs are limited to 39 characters and can contain no punctuation other than a period. In such case, a ProgID can be manually assigned to the class using ProgIdAttribute.


[Visual Basic, C#, C++] The following example demonstrates how to apply ProgIdAttribute on a class. The application then gets all attributes of MyClass, and prints the Value property of ProgIdAttribute.

[Visual Basic] 
<ClassInterface(ClassInterfaceType.AutoDispatch), ProgId("InteropSample.MyClass")>  _
Public Class [MyClass]
   Public Sub New()
   End Sub 'New
End Class '[MyClass]

Class TestApplication
   Public Shared Sub Main()
         Dim attributes As AttributeCollection
         attributes = TypeDescriptor.GetAttributes(GetType([MyClass]))
         Dim progIdAttributeObj As ProgIdAttribute = CType(attributes(GetType(ProgIdAttribute)), ProgIdAttribute)
         Console.WriteLine(("ProgIdAttribute's value is set to : " + progIdAttributeObj.Value))
      Catch e As Exception
         Console.WriteLine(("Exception : " + e.Message.ToString()))
      End Try
   End Sub 'Main
End Class 'TestApplication
End Namespace 'InteropSample 

public class MyClass
    public MyClass() {}

class TestApplication
   public static void Main()
         AttributeCollection attributes;
         attributes = TypeDescriptor.GetAttributes(typeof(MyClass));
         ProgIdAttribute progIdAttributeObj = (ProgIdAttribute)attributes[typeof(ProgIdAttribute)];
         Console.WriteLine("ProgIdAttribute's value is set to : " + progIdAttributeObj.Value);
      catch(Exception e)
         Console.WriteLine("Exception : " + e.Message);



       public __gc class MyClass {
         MyClass() {}

      int main() {

         try {
            AttributeCollection* attributes;
            attributes = TypeDescriptor::GetAttributes(__typeof(MyClass));
            ProgIdAttribute*  progIdAttributeObj = dynamic_cast<ProgIdAttribute *>(attributes->Item[__typeof(ProgIdAttribute)]);
            Console::WriteLine(S"ProgIdAttribute's value is set to : {0}", progIdAttributeObj->Value);
         } catch (Exception* e) {
            Console::WriteLine(S"Exception : {0}", e->Message);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Namespace: System.Runtime.InteropServices

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: Mscorlib (in Mscorlib.dll)

See Also

ProgIdAttribute Members | System.Runtime.InteropServices Namespace