Repository navigation
Description
Hello,
I'm using dotnet 9
I'm running the tests via dotnet test
- .runsetings file :
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> I use reportgenerator to view the coverage:
And for the record, there is an line matching the declaration of the record that is not covered
<function id="2625" name=".ctor(System.Guid)" namespace="CC.Core.Commands" type_name="GetRicFeedbackCommand" block_coverage="0.00" line_coverage="100.00" blocks_covered="0" blocks_not_covered="0" lines_covered="4" lines_partially_covered="0" lines_not_covered="0">
<ranges>
<range source_id="380" start_line="14" end_line="14" start_column="0" end_column="0" covered="yes" />
<range source_id="380" start_line="15" end_line="15" start_column="0" end_column="0" covered="yes" />
<range source_id="380" start_line="16" end_line="16" start_column="0" end_column="0" covered="yes" />
<range source_id="380" start_line="17" end_line="17" start_column="0" end_column="0" covered="yes" />
</ranges>
</function>
<function id="2626" name="get_WorkspaceKey()" namespace="CC.Core.Commands" type_name="GetRicFeedbackCommand" block_coverage="0.00" line_coverage="100.00" blocks_covered="0" blocks_not_covered="0" lines_covered="1" lines_partially_covered="0" lines_not_covered="0">
<ranges>
<range source_id="380" start_line="18" end_line="18" start_column="0" end_column="0" covered="yes" />
</ranges>
</function>
<function id="2627" name="set_WorkspaceKey(System.Guid)" namespace="CC.Core.Commands" type_name="GetRicFeedbackCommand" block_coverage="0.00" line_coverage="100.00" blocks_covered="0" blocks_not_covered="0" lines_covered="1" lines_partially_covered="0" lines_not_covered="0">
<ranges>
<range source_id="380" start_line="18" end_line="18" start_column="0" end_column="0" covered="yes" />
</ranges>
</function>
<function id="2628" name=".ctor(CC.Core.Commands.GetRicFeedbackCommand)" namespace="CC.Core.Commands" type_name="GetRicFeedbackCommand" block_coverage="0.00" line_coverage="0.00" blocks_covered="0" blocks_not_covered="0" lines_covered="0" lines_partially_covered="0" lines_not_covered="1">
<ranges>
<range source_id="380" start_line="12" end_line="12" start_column="0" end_column="0" covered="no" />
</ranges>
</function>=> .ctor(CC.Core.Commands.GetRicFeedbackCommand) => covered="no"
I already reported the issue on ReportGenerator project where the conclusion was that the issue came from the cobertura report, not reportgenerator danielpalme/ReportGenerator#749
And it seems coverlet gets it right danielpalme/ReportGenerator#749 (comment)
Does the issue come from Microsoft.CodeCoverage ? Am I posting the issue in the right repo ?
Is it a matter of "interpretation" (I understand that there is some generated "wiring code" generated for records which might not be covered) ?
Thank you for your help
Activity
Youssef1313 commentedon Aug 10, 2025
I think microsoft/codecoverage should be the right repo. Moving there.
fhnaseer commentedon Aug 11, 2025
A copy constructor is generated in case of record and for that coverage is zero.
This can be skipped if you set
SkipAutoPropertiesto true in runsettings file. However, this will be available in 18.0 version of code coverage which is not released yet. As a workaround, you can try to exclude this function from the coverage report using runsettings file. https://github.com/microsoft/codecoverage/blob/main/docs/configuration.mdtomap commentedon Aug 18, 2025
Hello,
Thank you for the advice, I've added the property, which will work with 18.0
In the meantime, I've added
It also works
fhnaseer commentedon Aug 18, 2025
Please keep this in mind that
System\.Runtime\.CompilerServices\.CompilerGeneratedAttributewill also exclude those functions for which you might want to have coverage e.g. lambdas.Lorilatschki commentedon Dec 19, 2025
fhnaseer we having the same issue and try to get rid of this behavior. We tried to use the suggested setting
SkipAutoPropertiesbut with no effect. We are using version18.0.6ofMicrosoft.Testing.Extensions.CodeCoverage.The above didn't worked, but this does:
Is there a way to change the default setting so that automatically generated properties/methods are ignored, as I cannot imagine that the majority would want such a metric to be part of the coverage data?
We do have many small repos in our project and switching it off by providing such a settings file for each and every repo is kind of to much effort. We have a central managed CI/CD pipeline, therefor a CLI parameter or a changed default value would help a lot.
fhnaseer commentedon Dec 19, 2025
I created a new MSTest 3.11.1 project with MS.Testing.Ext.CC 18.0.4 and is working fine.
SkipAutoProperties = true

SkipAutoProperties = false

Changing default to true will reduce number of lines in the coverage report which can affect users in different ways.
^System\.Runtime\.CompilerServices\.CompilerGeneratedAttribute$can also skip some other methods for which you want to calculate coverage for. In the CI/CD you can have one runsettings file for your whole repo and can use it to have consistent results.Lorilatschki commentedon Dec 19, 2025
fhnaseer in your example you are using the
<RunSettings>structure, not the simple subset of such a .runsettings file. Can you try use exactly this one?fhnaseer commentedon Dec 19, 2025
It should work same for both cases (full runsettings or only configuration).
Lorilatschki commentedon Dec 19, 2025
This doesn't work on our end. When running our tests with that, still the copy ctor is part of the coverage file. Maybe this is related to the used versions of dotnet and MTP, isn't it?
We are using the following versions:
xunit.v3with versionv3.2.1dotnet 8Microsoft.NET.Test.Sdkwith version18.0.1MTPwith version1.9.0Configuration File
coverage.config:Test execution output:
Test exeuction CLI:
dotnet run --project test/myTest.csproj -c Release --no-restore --coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml --results-directory ./test-result --no-progress --coverage-settings .\coverage.configThe final
coverage.cobertura.xmlstill has this line:Lorilatschki commentedon Dec 19, 2025
fhnaseer regarding
Nope, this is not that easy. As I said, we have 40+ repos, most of them don't have a
coverage.configfile defined, because there was currently no need for. Some already define such a coverage setting file, because they needed to override someModulePathwhich is unique for every repo. Therefore, we cannot easily use one central coverage setting file and we also don't want to introduce such a coverage setting file for each and every repo, just to get auto generated stuff hidden in the coverage result file.In our opinion, auto generated stuff should be opt out rather than opt in.
fhnaseer commentedon Dec 19, 2025
Its working fine for xunit as well.
Lorilatschki commentedon Dec 19, 2025
fhnaseer it took me a while, but I found out what the difference is. Can you please use this record here not the one from your example?
With that one in my demo project, and the setting
<SkipAutoProperties>True</SkipAutoProperties>it still gets the copy ctor generated.fhnaseer commentedon Dec 30, 2025
Lori (@Lorilatschki) Thanks for providing the sample. Your code does not contain any properties and hence skipping part is not evaluated during instrumentation. I have covered this scenario and copy constructor should be excluded from the report as well. It will be part of next release 18.3.
Before the change,
After the change,

Lorilatschki commentedon Dec 30, 2025
fhnaseer many thanks for the update and the fix. Regarding the desired change of the default behavior, is there a chance that the default behavior of system/compiler generated methods/properties didn't get instrumented (so opt out) and can be turned on by defining a new setting?
fhnaseer commentedon Dec 30, 2025
We do exclude some attributes by default which also includes GeneratedCode attribute.
But the one in question in this scenario is
System.Runtime.CompilerServices.CompilerGeneratedAttribute. This attribute is also part of other generated methods, and we are interested in collecting coverage for these methods. That's why this is not part of the default exclusion list.Regarding making
<SkipAutoProperties>totrueby default is a breaking change. Since, it is a newly introduced feature, we don't to set this to true right now.Lorilatschki commentedon Dec 30, 2025
Would it be possble, to enable setup such coverage settings via environment variables, e.g.
CC_SkipAutoProperties? This would help us a lot, since we can override this settings in one place, our gitlab ci/cd template. In case it is defined in a given settings file as well as through an environment variable, the settings file has precedence.fhnaseer commentedon Jan 2, 2026
This is not supported. We recommended having different config files for different environments.
rcollette commentedon Feb 17, 2026
Something important to note. The Microsoft.NET.Test.Sdk version needs to be at 18 as well.
I updated from 17.12.0 to 18.0.1 along with the SkipAutoProperties runsetting set to false and that fixed the issue.
Pre
Post