Skip to content

ExcludeFromCodeCoverageAttribute can't be applied to interfaces #123405

@mconnew

Description

@mconnew

Description

With interfaces now having the ability to have default implementations members, they can now contain code, which can show up on a code coverage report. The AttributeUsage attribute on ExcludeFromCodeCoverageAttribute does not specify AttributeTargets.Interface so applying the attribute to an interface will cause a compiler error.

Reproduction Steps

Try to compile the following code:

[ExcludeFromCodeCoverage]
public interface ILogger
{
    void Log(string message);

    // Default interface method (C# 8+)
    void LogWarning(string message)
        => Log($"[WARN] {message}");
}

Expected behavior

The provided sample code to be compiled without error.

Actual behavior

You will get a compilation error as ExcludeFromCodeCoverageAttribute can't be applied to an interface.

Regression?

No regression

Known Workarounds

I would expect applying the attribute to the individual method implementations would work.

Configuration

All versions of .NET, any OS, any architecture.

Other information

Missing AttributeTargets.Interface on the AttributeUsage attribute of ExcludeFromCodeCoverageAttribute.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions