Skip to content

[GeneratedComInterface] in CCW-only mode produces CA2256 warning #90922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Tracked by #114179
Sergio0694 opened this issue Aug 22, 2023 · 4 comments · Fixed by #114642
Closed
Tracked by #114179

[GeneratedComInterface] in CCW-only mode produces CA2256 warning #90922

Sergio0694 opened this issue Aug 22, 2023 · 4 comments · Fixed by #114642
Labels
area-System.Runtime.InteropServices in-pr There is an active PR which will close this issue when it is merged
Milestone

Comments

@Sergio0694
Copy link
Contributor

Sergio0694 commented Aug 22, 2023

Description

When using [GeneratedComInterface] with ComInterfaceOptions.ManagedObjectWrapper, the generator emits an empty interface declaration with [DynamicInterfaceCastableImplementation], which then produces a warning:

Reproduction Steps

[Guid("7448E99B-0904-4B6A-9CC2-51DD9A71032A")]
[GeneratedComInterface(Options = ComInterfaceOptions.ManagedObjectWrapper)]
public partial interface IFoo
{
    void Foo();
}

Expected behavior

No build warnings or errors.

Actual behavior

"Microsoft.Interop.ComInterfaceGenerator\IFoo.cs(12,31,12,54): warning CA2256: Type 'InterfaceImplementation' has the 'DynamicInterfaceCastableImplementationAttribute' applied to it but does not provide an implementation of all interface members defined in inherited interfaces (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2256)"

Regression?

No, it's a new feature.

Configuration

  • VS 17.8 Preview 1
  • .NET 8.0.100-rc.2.23421.16
  • Roslyn 4.8.0-1.23377.4 (692d17e9)
@ghost ghost added needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners untriaged New issue has not been triaged by the area owner labels Aug 22, 2023
@MihaZupan MihaZupan added area-System.Runtime.InteropServices and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Aug 22, 2023
@ghost
Copy link

ghost commented Aug 22, 2023

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

When using [GeneratedComInterface] with ComInterfaceOptions.ManagedObjectWrapper, the generator emits an empty interface declaration with [DynamicInterfaceCastableImplementation], which then produces a warning:

Reproduction Steps

[Guid("7448E99B-0904-4B6A-9CC2-51DD9A71032A")]
[GeneratedComInterface(Options = ComInterfaceOptions.ManagedObjectWrapper)]
public partial interface IFoo
{
    void Foo();
}

Expected behavior

No build warnings or errors.

Actual behavior

"Microsoft.Interop.ComInterfaceGenerator\IFoo.cs(12,31,12,54): warning CA2256: Type 'InterfaceImplementation' has the 'DynamicInterfaceCastableImplementationAttribute' applied to it but does not provide an implementation of all interface members defined in inherited interfaces (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2256)"

Regression?

No, it's a new feature.

Configuration

  • VS 17.8 Preview 1
  • .NET 8.0.100-rc.2.23421.16
  • Roslyn 4.8.0-1.23377.4 (692d17e9)
Author: Sergio0694
Assignees: -
Labels:

area-System.Runtime.InteropServices, untriaged

Milestone: -

@AaronRobinsonMSFT AaronRobinsonMSFT changed the title [GeneratedComInterface] in RCW-only mode produces CA2256 warning [GeneratedComInterface] in CCW-only mode produces CA2256 warning Aug 23, 2023
@AaronRobinsonMSFT AaronRobinsonMSFT removed the untriaged New issue has not been triaged by the area owner label Aug 23, 2023
@AaronRobinsonMSFT AaronRobinsonMSFT added this to the 9.0.0 milestone Aug 23, 2023
@smaillet
Copy link

It's been almost a year, and this issue is still present in latest releases. What's the status? Can someone who actually understands the generated code and attribute explain if this is at least safe to ignore?

@smaillet
Copy link

So, I found a workaround at least, for anyone else seeing this. In a GlobalSupporession.cs file add the following assembly level suppression. This will, fortunately silence all of these warnings in generated code where the type InterfaceImplemantation is declared with the file modifier in the
global namespace.

using System.Diagnostics.CodeAnalysis;

// Until https://github.com/dotnet/runtime/issues/90922 is resolved, this is the only way
// to suppress the warning in the generated code. The analyzer is ignoring that it is
// generated, and partial (where the declarations live in a different partial class
// [in the same "file"])
[assembly: SuppressMessage(
    "Usage",
    "CA2256:All members declared in parent interfaces must have an implementation in a DynamicInterfaceCastableImplementation-attributed interface",
    Justification = "Generated Code and analyzer ignores that it is generated AND partial",
    Scope = "type",
    Target = "~T:InterfaceImplementation")
]

Since the generated code uses the file modifier on a symbol in the global namespace, this single suppression applies to them all.

@Sergio0694
Copy link
Contributor Author

@jkoritzinsky adding this to #114179 since we're now hitting this in CsWinRT as well. Not a blocker though, just tracking it 🙂

@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Apr 14, 2025
@github-actions github-actions bot locked and limited conversation to collaborators May 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Runtime.InteropServices in-pr There is an active PR which will close this issue when it is merged
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants