Open Sergio0694 opened 1 year ago
Tagging subscribers to this area: @dotnet/interop-contrib See info in area-owners.md if you want to be subscribed.
Author: | Sergio0694 |
---|---|
Assignees: | - |
Labels: | `area-System.Runtime.InteropServices`, `untriaged` |
Milestone: | - |
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?
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.
Description
When using
[GeneratedComInterface]
withComInterfaceOptions.ManagedObjectWrapper
, the generator emits an empty interface declaration with[DynamicInterfaceCastableImplementation]
, which then produces a warning:Reproduction Steps
Expected behavior
No build warnings or errors.
Actual behavior
Regression?
No, it's a new feature.
Configuration