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

Aperta
#200 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@fhnaseer ci sta già lavorando.

Dal 5/1/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

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.

Lingua principale
C#
Stelle
125
Fork
17
Merge medio
1h 17m
PR unite (30g)
2

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/codecoverage

Tutte le issue di microsoft/codecoverage

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.