Microsoft.CodeCoverage.MSBuild introduces new trim warnings in otherwise trim-safe project

Đang mở
#200 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

@fhnaseer đang làm issue này rồi.

Từ ngày 5/1/2026.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

Describe the bug

Adding static code coverage instrumentation to a NativeAOT test binary introduces trim warnings where there were none before.

My guess is whatever IL rewriting is going on for static code analysis, it isn't applying appropriate attributes to the modified code to preserve trim safety.

Steps To Reproduce

git clone -b tunit-code-coverage git@github.com:AArnott/Nerdbank.MessagePack.git
cd Nerdbank.MessagePack
./init.ps1
dotnet publish -f net10.0 .\test\Nerdbank.MessagePack.TUnit\

Expected behavior

No trim warnings.

Actual behavior

  Nerdbank.MessagePack.TUnit net10.0 win-x64 succeeded with 3 warning(s) (26.3s) → bin\Nerdbank.MessagePack.TUnit\Debug\net10.0\win-x64\publish\
    E:\src\nerdbank.messagepack\src\Nerdbank.MessagePack\ConverterTypeCollection.cs(116): Trim analysis warning IL2078: Nerdbank.MessagePack.ConverterTypeCollection.ConverterType.Type.get: 'Nerdbank.MessagePack.ConverterTypeCollection.ConverterType.Type.get' method return value does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' requirements. The field 'Nerdbank.MessagePack.ConverterTypeCollection.ConverterType.<Type>k__BackingField' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
    E:\src\nerdbank.messagepack\src\Nerdbank.MessagePack\UseComparerAttribute.cs(56): Trim analysis warning IL2078: Nerdbank.MessagePack.UseComparerAttribute.ComparerType.get: 'Nerdbank.MessagePack.UseComparerAttribute.ComparerType.get' method return value does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor', 'DynamicallyAccessedMemberTypes.PublicProperties' requirements. The field 'Nerdbank.MessagePack.UseComparerAttribute.<ComparerType>k__BackingField' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
    E:\src\nerdbank.messagepack\src\Nerdbank.MessagePack\MessagePackConverterAttribute.cs(32): Trim analysis warning IL2078: Nerdbank.MessagePack.MessagePackConverterAttribute.ConverterType.get: 'Nerdbank.MessagePack.MessagePackConverterAttribute.ConverterType.get' method return value does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' requirements. The field 'Nerdbank.MessagePack.MessagePackConverterAttribute.<ConverterType>k__BackingField' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.

Additional context

If you run git checkout HEAD~1 and then repeat the publish command, you can see how the trim warnings disappear.
The only difference is you've removed the last commit, which is what added the Microsoft.CodeCoverage.MSBuild package dependency and AotMsCodeCoverageInstrumentation property.

Ngôn ngữ chính
C#
Star
125
Fork
17
Merge trung bình
1 giờ 17 phút
Pull request đã merge (30 ngày)
2

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/codecoverage

Tất cả issue của microsoft/codecoverage

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.