`CompilerGeneratedAttribute` excludes new class
See original GitHub issueHello!
We have a strange issue in our project.
We added a new class that basically looks like this:
using MediatR;
using System.Transactions;
using ORG.PROJECT.OTHERPACKAGE;
namespace ORG.PROJECT.PACKAGE.Behaviours;
public class TransactionBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
where TRequest : IRequest<TResponse>, ITransactionCommand
{
public async Task<TResponse> Handle(
TRequest request,
RequestHandlerDelegate<TResponse> next,
CancellationToken cancellationToken)
{
using (var scope = new TransactionScope(
TransactionScopeOption.Required,
new TransactionOptions { IsolationLevel = request.TransactionIsolationLevel },
TransactionScopeAsyncFlowOption.Enabled
))
{
var result = await next();
scope.Complete();
return result;
}
}
}
This new class (&method) does not show up in our code coverage report: I also already ruled out any display or converting issues (report generator), it is definitely already missing in the opencover file, we get from our build.
However, all other classes from that package are found. The strange thing is, that our other Behaviours classes are really similar. Like same generics, same method definition and so on. The only difference would be our ITransactionCommand
interface, but also already tried removing that.
After some digging I found out, that this class gets excluded with the CompilerGeneratedAttribute
Our test execution looks like this:
- task: DotNetCoreCLI@2
displayName: Test application
inputs:
command: test
projects: '**/*Tests/*.csproj'
arguments: >-
--configuration $(buildConfiguration)
--collect:"XPlat Code Coverage"
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.ExcludeByFile=**/Migrations/*.cs
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.ExcludeByAttribute=Obsolete,GeneratedCodeAttribute,CompilerGeneratedAttribute
As soon as I remove the CompilerGeneratedAttribute
from the ExcludedByAttribute
list, the new class gets detected.
Our environment:
- .NET 7.0.2
- Microsoft.NET.Test.Sdk 17.4.1
- xunit 2.4.2
- xunit.runner.visualstudio 2.4.5
- coverlet.collector 3.2.0
- Ubuntu 22.04
This looks like a bug to me and to be honest, I have zero clue, why it is behaving in that way. Some differences to our other behaviours:
- Dependency to
System.Transactions
using
statement forIDisposable
- Only this one
Handle
method, instead of multiple methods (that are called by theHandle
method)
Apparently this was already a problem in the past: https://github.com/coverlet-coverage/coverlet/issues/794
If needed, I can try to create a minimal reproducible repo.
Issue Analytics
- State:
- Created 8 months ago
- Comments:7
Top GitHub Comments
We cannot do a lot for it as @daveMueller explained, I also suggest to remove the attribute and handle the “noise” with other filtering.
Yes I would advise to remove it. Only thing that I have in mind are auto-implemented properties that after removing could be reported as uncovered (instead of beeing skipped). But therefore there is the
SkipAutoProps
option (https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/MSBuildIntegration.md#skip-auto-implemented-properties).@petli @MarcoRossignoli @tonerdo Any other thoughts on this?