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 |
|
|
mikejo5000 |
mikejo |
mijacobs |
code-analysis |
|
vs-2019 |
Item | Value |
---|---|
RuleId | CA1412 |
Category | Microsoft.Interoperability |
Breaking change | Breaking |
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.
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.
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.
Do not suppress a warning from this rule.
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":::