Skip to content

Latest commit

 

History

History
65 lines (45 loc) · 2.56 KB

ca1412.md

File metadata and controls

65 lines (45 loc) · 2.56 KB
title description ms.date ms.topic f1_keywords helpviewer_keywords author ms.author manager ms.subservice dev_langs monikerRange
CA1412: Mark ComSource Interfaces as IDispatch
A type is marked with the System.Runtime.InteropServices.ComSourceInterfacesAttribute attribute and at least one specified interface is not marked with the System.Runtime.InteropServices.InterfaceTypeAttribute attribute set to the InterfaceIsDispatch value.
11/04/2016
reference
MarkComSourceInterfacesAsIDispatch
CA1412
CA1412
MarkComSourceInterfacesAsIDispatch
mikejo5000
mikejo
mijacobs
code-analysis
CSharp
VB
vs-2019

CA1412: Mark ComSource Interfaces as IDispatch

Item Value
RuleId CA1412
Category Microsoft.Interoperability
Breaking change Breaking

Cause

A type is marked with the xref:System.Runtime.InteropServices.ComSourceInterfacesAttribute attribute and at least one specified interface is not marked with the xref:System.Runtime.InteropServices.InterfaceTypeAttribute attribute set to the InterfaceIsDispatch value.

Rule description

xref:System.Runtime.InteropServices.ComSourceInterfacesAttribute is used to identify the event interfaces that a class exposes to Component Object Model (COM) clients. These interfaces must be exposed as InterfaceIsIDispatch to enable Visual Basic 6 COM clients to receive event notifications. By default, if an interface is not marked with the xref:System.Runtime.InteropServices.InterfaceTypeAttribute attribute, it is exposed as a dual interface.

How to fix violations

To fix a violation of this rule, add, or modify the xref:System.Runtime.InteropServices.InterfaceTypeAttribute attribute so that its value is set to InterfaceIsIDispatch for all interfaces that are specified with the xref:System.Runtime.InteropServices.ComSourceInterfacesAttribute attribute.

When to suppress warnings

Do not suppress a warning from this rule.

Example

The following example shows a class where one of the interfaces violates the rule.

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

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

Related rules

CA1408: Do not use AutoDual ClassInterfaceType

See also