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 |
|
|
mikejo5000 |
mikejo |
mijacobs |
code-analysis |
|
vs-2019 |
Item | Value |
---|---|
RuleId | CA1410 |
Category | Microsoft.Interoperability |
Breaking change | Non-breaking |
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.
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.
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.
:::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":::
CA1411: COM registration methods should not be visible
- xref:System.Runtime.InteropServices.RegistrationServices?displayProperty=fullName
- Register Assemblies with COM
- Regasm.exe (Assembly Registration Tool)