CA1410: COM registration methods should be matched

 

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

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

TypeNameComRegistrationMethodsShouldBeMatched
CheckIdCA1410
CategoryMicrosoft.Interoperability
Breaking ChangeNon-breaking

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

For Component Object Model (COM) clients to create a .NET Framework type, the type must first be registered. If it is available, a method that is marked with the ComRegisterFunctionAttribute attribute is called during the registration process to run user-specified code. A corresponding method that is 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.

using System;
using System.Runtime.InteropServices;

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

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

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

CA1411: COM registration methods should not be visible

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

Show: