COM registration methods should be matched
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

COM registration methods should be matched







Breaking Change

Non Breaking

A type declares a method marked with the System.Runtime.InteropServices.ComRegisterFunctionAttribute attribute but does not declare a method marked with the System.Runtime.InteropServices.ComUnregisterFunctionAttribute attribute, or vice versa.

For COM clients to create a .NET Framework type, the type must first be registered. If it is available, a method marked with the ComRegisterFunctionAttribute attribute is called during the registration process to run user specified code. A corresponding method marked with the ComUnregisterFunctionAttribute attribute is called during the unregistration process to reverse the operations of the registration method.

To fix a violation of this rule add the corresponding registration or unregistration method.

Do not suppress a warning from this rule.

The following example shows a type that violates the rule. The commented code shows the fix for the violation.

Imports System
Imports System.Runtime.InteropServices

<Assembly: ComVisibleAttribute(True)>
Namespace InteroperabilityLibrary

   Public Class ClassToRegister
   End Class 

   Public Class ComRegistration

      <ComRegisterFunctionAttribute> _ 
      Friend Shared Sub RegisterFunction(typeToRegister As Type)
      End Sub 

'      <ComUnregisterFunctionAttribute> _  
'      Friend Shared Sub UnregisterFunction(typeToRegister As Type) 
'      End Sub 

   End Class 

End Namespace
© 2015 Microsoft