Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
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.

COM registration methods should not be visible

TypeName

ComRegistrationMethodsShouldNotBeVisible

CheckId

CA1411

Category

Microsoft.Interoperability

Breaking Change

Breaking

When an assembly is registered with COM, entries are added to the registry for each of the COM visible types in the assembly. Methods marked with the ComRegisterFunctionAttribute and ComUnregisterFunctionAttribute attributes are called during the registration and unregistration processes, respectively, to run user code that is specific to the registration/unregistration of these types. This code should not called outside these processes.

To fix a violation of this rule change the accessibility of the method to private or internal (Friend in Visual Basic).

Do not suppress a warning from this rule.

The following example shows two methods that violate the rule.

Imports System
Imports System.Runtime.InteropServices

<Assembly: ComVisibleAttribute(True)>
Namespace InteroperabilityLibrary

   Public Class ClassToRegister
   End Class 

   Public Class ComRegistration

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

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

   End Class 

End Namespace

Community Additions

ADD
Show:
© 2015 Microsoft