Skip to content

Latest commit

 

History

History
62 lines (43 loc) · 2.46 KB

ca1405.md

File metadata and controls

62 lines (43 loc) · 2.46 KB
title description ms.date ms.topic f1_keywords helpviewer_keywords author ms.author manager ms.subservice dev_langs
CA1405: COM visible type base types should be COM visible
A Component Object Model (COM) visible type derives from a type that is not COM visible.
11/04/2016
reference
CA1405
ComVisibleTypeBaseTypesShouldBeComVisible
CA1405
ComVisibleTypeBaseTypesShouldBeComVisible
mikejo5000
mikejo
mijacobs
code-analysis
CSharp
VB

CA1405: COM visible type base types should be COM visible

Item Value
RuleId CA1405
Category Microsoft.Interoperability
Breaking change DependsOnFix

Cause

A Component Object Model (COM) visible type derives from a type that is not COM visible.

Rule description

When a COM visible type adds members in a new version, it must abide by strict guidelines to avoid breaking COM clients that bind to the current version. A type that is invisible to COM presumes it does not have to follow these COM versioning rules when it adds new members. However, if a COM visible type derives from the COM invisible type and exposes a class interface of xref:System.Runtime.InteropServices.ClassInterfaceType?displayProperty=fullName or xref:System.Runtime.InteropServices.ClassInterfaceType (the default), all public members of the base type (unless they are specifically marked as COM invisible, which would be redundant) are exposed to COM. If the base type adds new members in a subsequent version, any COM clients that bind to the class interface of the derived type might break. COM visible types should derive only from COM visible types to reduce the chance of breaking COM clients.

How to fix violations

To fix a violation of this rule, make the base types COM visible or the derived type COM invisible.

When to suppress warnings

Do not suppress a warning from this rule.

Example

The following example shows a type that violates the rule.

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

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

See also