Skip to content

Latest commit

 

History

History
67 lines (47 loc) · 2.69 KB

ca1410.md

File metadata and controls

67 lines (47 loc) · 2.69 KB
title description ms.date ms.topic f1_keywords helpviewer_keywords author ms.author manager ms.subservice dev_langs monikerRange
CA1410: COM registration methods should be matched
A type declares a method that is marked with the ComRegisterFunction attribute but does not declare a method that is marked with the ComUnregisterFunction attribute, or vice versa.
11/04/2016
reference
CA1410
ComRegistrationMethodsShouldBeMatched
CA1410
ComRegistrationMethodsShouldBeMatched
mikejo5000
mikejo
mijacobs
code-analysis
CSharp
VB
vs-2019

CA1410: COM registration methods should be matched

Item Value
RuleId CA1410
Category Microsoft.Interoperability
Breaking change Non-breaking

Cause

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

Rule description

For Component Object Model (COM) clients to create a .NET type, the type must first be registered. If it is available, a method that is marked with the xref:System.Runtime.InteropServices.ComRegisterFunctionAttribute attribute is called during the registration process to run user-specified code. A corresponding method that is marked with the xref:System.Runtime.InteropServices.ComUnregisterFunctionAttribute attribute is called during the unregistration process to reverse the operations of the registration method.

How to fix violations

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

When to suppress warnings

Do not suppress a warning from this rule.

Example

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

:::code language="csharp" source="../snippets/csharp/VS_Snippets_CodeAnalysis/FxCop.Interoperability.ComRegistration/cs/FxCop.Interoperability.ComRegistration.cs" id="Snippet1":::

:::code language="vb" source="../snippets/visualbasic/VS_Snippets_CodeAnalysis/FxCop.Interoperability.ComRegistration/vb/FxCop.Interoperability.ComRegistration.vb" id="Snippet1":::

Related rules

CA1411: COM registration methods should not be visible

See also