COM registration methods should be matched
TypeName | ComRegistrationMethodsShouldBeMatched |
CheckId | CA1410 |
Category | Microsoft.Interoperability |
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.
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) {} } }