CA1411: COM registration methods should not be visible

 

For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.

For the latest documentation on Visual Studio 2017, see CA1411: COM registration methods should not be visible on docs.microsoft.com.

TypeNameComRegistrationMethodsShouldNotBeVisible
CheckIdCA1411
CategoryMicrosoft.Interoperability
Breaking ChangeBreaking

A method that is marked with the System.Runtime.InteropServices.ComRegisterFunctionAttribute or the System.Runtime.InteropServices.ComUnregisterFunctionAttribute attribute is externally visible.

When an assembly is registered with Component Object Model (COM), entries are added to the registry for each COM-visible type in the assembly. Methods that are 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 be 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.

using System;
using System.Runtime.InteropServices;

[assembly: ComVisible(true)]
namespace InteroperabilityLibrary
{
   public class ClassToRegister
   {
   }

   public class ComRegistration
   {
      [ComRegisterFunction]
      public static void RegisterFunction(Type typeToRegister) {}

      [ComUnregisterFunction]
      public static void UnregisterFunction(Type typeToRegister) {}
   }
}

CA1410: COM registration methods should be matched

System.Runtime.InteropServices.RegistrationServices
Registering Assemblies with COM
Regasm.exe (Assembly Registration Tool)

Show: