Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/fundamentals/code-analysis/quality-rules/ca2256.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ helpviewer_keywords:
- DynamicInterfaceCastableImplementationAnalyzer
- CA2256
author: Youssef1313
dev_langs:
- CSharp
---
# CA2256: All members declared in parent interfaces must have an implementation in a DynamicInterfaceCastableImplementation-attributed interface

Expand All @@ -32,10 +34,15 @@ Types attributed with <xref:System.Runtime.InteropServices.DynamicInterfaceCasta

Implement the missing interface members.

## Example

:::code language="csharp" source="snippets/csharp/all-rules/ca2256.cs" id="snippet1" highlight="30":::

## When to suppress errors

Do not suppress a warning from this rule.

## See also

- [Usage warnings](usage-warnings.md)
- [CA2257: Members defined on an interface with the 'DynamicInterfaceCastableImplementationAttribute' should be 'static'](ca2257.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Runtime.InteropServices;

namespace ca2256
{
//<snippet1>
interface IParent
{
void ParentMethod();
}

// This interface violates the rule.
[DynamicInterfaceCastableImplementation]
interface IBadChild : IParent
{
static void ChildMethod()
{
// ...
}
}

// This interface satisfies the rule.
[DynamicInterfaceCastableImplementation]
interface IGoodChild : IParent
{
static void ChildMethod()
{
// ...
}

void IParent.ParentMethod()
{
// ...
}
}
//</snippet1>
}