.NET Framework Class Library
ComRegisterFunctionAttribute Class

Specifies the method to call when you register an assembly for use from COM; this enables the execution of user-written code during the registration process.

Inheritance Hierarchy

Namespace:   System.Runtime.InteropServices
Assembly:  mscorlib (in mscorlib.dll)
<[%$TOPIC/8xhz6f68_en-us_VS_110_2_0_0_0_0%]([%$TOPIC/8xhz6f68_en-us_VS_110_2_0_0_0_1%].Method, Inherited := False)> _
<[%$TOPIC/8xhz6f68_en-us_VS_110_2_0_0_0_2%](True)> _
Public NotInheritable Class ComRegisterFunctionAttribute _
	Inherits [%$TOPIC/8xhz6f68_en-us_VS_110_2_0_0_0_3%]
[[%$TOPIC/8xhz6f68_en-us_VS_110_2_0_1_0_0%]([%$TOPIC/8xhz6f68_en-us_VS_110_2_0_1_0_1%].Method, Inherited = false)]
public sealed class ComRegisterFunctionAttribute : [%$TOPIC/8xhz6f68_en-us_VS_110_2_0_1_0_3%]
[[%$TOPIC/8xhz6f68_en-us_VS_110_2_0_2_0_0%]([%$TOPIC/8xhz6f68_en-us_VS_110_2_0_2_0_1%]::Method, Inherited = false)]
public ref class ComRegisterFunctionAttribute sealed : public [%$TOPIC/8xhz6f68_en-us_VS_110_2_0_2_0_3%]
[<[%$TOPIC/8xhz6f68_en-us_VS_110_2_0_3_0_1%]([%$TOPIC/8xhz6f68_en-us_VS_110_2_0_3_0_2%].Method, Inherited = false)>]
type ComRegisterFunctionAttribute =  
        inherit [%$TOPIC/8xhz6f68_en-us_VS_110_2_0_3_0_4%] 
public final class ComRegisterFunctionAttribute extends [%$TOPIC/8xhz6f68_en-us_VS_110_2_0_4_0_0%]

The ComRegisterFunctionAttribute type exposes the following members.

Public method ComRegisterFunctionAttributeInitializes a new instance of the ComRegisterFunctionAttribute class.
Public property TypeIdWhen implemented in a derived class, gets a unique identifier for this Attribute. (Inherited from Attribute.)
Public method EqualsInfrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)
Public method GetHashCodeReturns the hash code for this instance. (Inherited from Attribute.)
Public method GetTypeGets the Type of the current instance. (Inherited from Object.)
Public method IsDefaultAttributeWhen overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute.)
Public method MatchWhen overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
Public method ToStringReturns a string that represents the current object. (Inherited from Object.)
Explicit Interface Implementations
Explicit interface implemetation Private method _AttributeGetIDsOfNamesMaps a set of names to a corresponding set of dispatch identifiers. (Inherited from Attribute.)
Explicit interface implemetation Private method _AttributeGetTypeInfoRetrieves the type information for an object, which can be used to get the type information for an interface. (Inherited from Attribute.)
Explicit interface implemetation Private method _AttributeGetTypeInfoCountRetrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from Attribute.)
Explicit interface implemetation Private method _AttributeInvokeProvides access to properties and methods exposed by an object. (Inherited from Attribute.)

You can apply this attribute to methods.

ComRegisterFunctionAttribute enables you to add arbitrary registration code to accommodate the requirements of COM clients. For example, you can update the registry using registration functions from the Microsoft.Win32 namespace. If you provide a registration method, you must also apply System.Runtime.InteropServicesComUnregisterFunctionAttribute to an unregistration method, which reverses the operations done in the registration method.

The common language runtime calls the method with this attribute when its containing assembly is registered (directly or indirectly) with the Regasm.exe (Assembly Registration Tool)or through the RegistrationServicesRegisterAssembly method.

This attribute can be applied only to methods that have the following characteristics:

  • Scope: Any (public, private, and so on).

  • Type: static.

  • Parameters: Accepts a single Type parameter or a String parameter type.

  • Return type: void.


The following example demonstrates how to apply ComRegisterFunctionAttribute and ComUnregisterFunctionAttribute to methods with the appropriate signature.

Imports System
Imports System.Runtime.InteropServices

Public Class MyClassThatNeedsToRegister

    <ComRegisterFunctionAttribute()> Public Shared Sub _
      RegisterFunction(t As Type)
        'Insert code here. 
    End Sub

    <ComUnregisterFunctionAttribute()> Public Shared Sub _
      UnregisterFunction(t As Type)
        'Insert code here. 
    End Sub 
End Class
using System;
using System.Runtime.InteropServices;

public class MyClassThatNeedsToRegister
   public static void RegisterFunction(Type t)
      //Insert code here.

   public static void UnregisterFunction(Type t)
      //Insert code here.
using namespace System;
using namespace System::Runtime::InteropServices;
public ref class MyClassThatNeedsToRegister

   static void RegisterFunction( Type^ t )

      //Insert code here.

   static void UnregisterFunction( Type^ t )

      //Insert code here.

Version Information

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
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.