This documentation is archived and is not being maintained.

ComUnregisterFunctionAttribute Class

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

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

System.Object
   System.Attribute
      System.Runtime.InteropServices.ComUnregisterFunctionAttribute

[Visual Basic]
<AttributeUsage(AttributeTargets.Method)>
NotInheritable Public Class ComUnregisterFunctionAttribute
   Inherits Attribute
[C#]
[AttributeUsage(AttributeTargets.Method)]
public sealed class ComUnregisterFunctionAttribute : Attribute
[C++]
[AttributeUsage(AttributeTargets::Method)]
public __gc __sealed class ComUnregisterFunctionAttribute : public
   Attribute
[JScript]
public
   AttributeUsage(AttributeTargets.Method)
class ComUnregisterFunctionAttribute 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.

Remarks

You can apply this attribute to methods.

ComUnregisterFunctionAttribute enables you to add code that reverses the operations performed by a registration method. If you apply the ComRegisterFunctionAttribute to provide a registration method, you must also provide an unregistration method to reverse the operations done in the registration method. You can have only one unregistration method for a class.

The common language runtime calls the method with this attribute when its containing assembly is unregistered (directly or indirectly) with the Assembly Registration Tool (Regasm.exe) or through the RegistrationServices.UnregisterAssembly API method. Methods with this attribute can have any visibility (public, private, and so on), but must be static (Shared in Visual Basic) and must take a single Type parameter for the Type to unregister.

Example

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

[Visual Basic] 
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

[C#] 
using System;
using System.Runtime.InteropServices;

public class MyClassThatNeedsToRegister
{
   [ComRegisterFunctionAttribute]
   public static void RegisterFunction(Type t)
   {
      //Insert code here.
   }
   
   [ComUnregisterFunctionAttribute]
   public static void UnregisterFunction(Type t)
   {
      //Insert code here.
   }
}

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::Runtime::InteropServices;

public __gc class MyClassThatNeedsToRegister
{
public:
   [ComRegisterFunctionAttribute]
   static void RegisterFunction(Type* t)
   {
      //Insert code here.
   }
   
public:
   [ComUnregisterFunctionAttribute]
   static void UnregisterFunction(Type* t)
   {
      //Insert code here.
   }
};

[JScript] 
import System;
import System.Runtime.InteropServices;

public class MyClassThatNeedsToRegister
{
   ComRegisterFunctionAttribute public static function RegisterFunction(t : Type) : void 
   {
      //Insert code here.
   }
   
   ComUnregisterFunctionAttribute public static function UnregisterFunction(t : Type) : void
   {
      //Insert code here.
   }
}

Requirements

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

ComUnregisterFunctionAttribute Members | System.Runtime.InteropServices Namespace | ComRegisterFunctionAttribute | Assembly Registration Tool (Regasm.exe) | RegistrationServices.UnregisterAssembly

Show: