Skip to content

[BUG] .NET 9 generated logger methods with ExcludeByAttribute GeneratedCodeAttribute causes no coverage to be gathered #1756

Open
@tillig

Description

@tillig

Describe the bug

Given a project in .NET 9 using compiler generated logging methods, if you specify ExcludeByAttribute with GeneratedCodeAttribute, it causes no coverage to be collected for the entire assembly.

To Reproduce

Repro repository here to help illustrate the problem.

  • Create a .NET 9 project.
  • Add a partial class that has an ILogger private readonly field and a generated LoggerMessage based method.
  • Add a .runsettings file that has <ExcludeByAttribute>GeneratedCodeAttribute</ExcludeByAttribute>.
  • Run tests using that .runsettings file and collect coverage.

No coverage will be collected. If you either remove the generated method OR remove ExcludeByAttribute from the .runsettings file you can get coverage again.

Note it fails to capture coverage for anything. It doesn't only affect the one class with the generated method.

Expected behavior

Coverage should still be gathered, just not for the generated logging methods.

Actual behavior

No coverage at all is gathered, even for classes without the generated methods.

Configuration (please complete the following information):
Please provide more information on your .NET configuration:

  • Which coverlet package and version was used? coverlet.collector 6.0.4
  • Which version of .NET is the code running on? 9.0.203
  • What OS and version, and what distro if applicable? MacOS Sequoia 15.5
  • What is the architecture (x64, x86, ARM, ARM64)? ARM64
  • Do you know whether it is specific to that configuration? No

Metadata

Metadata

Assignees

No one assigned

    Labels

    untriagedTo be investigated

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions