Fix silently empty coverage for shared-framework assemblies missing from compileLibraries - #2032
Merged
Bertk merged 1 commit intoSep 22, 2026
Conversation
…rom compileLibraries TryWithCustomResolverOnDotNetCore in CecilAssemblyResolver only resolves assemblies by looking them up in DependencyContext.CompileLibraries (built from the instrumented module's *.deps.json). Starting with the .NET SDK 10.0.4xx feature band, transitively shared Microsoft.Extensions.* assemblies (e.g. Microsoft.Extensions.Logging, referenced only via a transitive FrameworkReference to Microsoft.AspNetCore.App, not directly on the instrumented project) are no longer enumerated in compileLibraries at all. When a method has a default parameter of such a shared-framework enum type, Cecil's resolver misses it and throws CecilAssemblyResolutionException while instrumenting -- and that failure silently drops the entire module out of the coverage report (coverage.cobertura.xml ends up with an empty <packages/>) even though `dotnet test` itself is green, with no diagnostic pointing at the real cause. NetCoreSharedFrameworkResolver already exists in the same file and can resolve these assemblies directly from the shared-framework directory via runtimeconfig.json, but it was only ever consulted as a constructor fallback, never re-tried when the compileLibraries lookup specifically misses by name. This change adds that fallback: on a compileLibraries miss, ask NetCoreSharedFrameworkResolver directly before giving up. Verified against a live repro matching the reporter's stack trace (CecilAssemblyResolutionException -> Mono.Cecil.MetadataBuilder.GetConstantType) on dotnet SDK 10.0.400/10.0.401 (the same feature band as the report). Added TestInstrument_NetstandardAwareAssemblyResolver_MissingFromCompileLibrariesFallsBackToSharedFramework, modeled on the neighboring _SiblingRuntimeConfigCanResolveSharedFrameworkAssembly test: a module with no adjacent .deps.json forces the compileLibraries lookup to miss, and the test asserts System.Text.Json still resolves via NetCoreSharedFrameworkResolver. 5/5 green on net10.0 (net8.0 leg not run in this environment: the SDK image only ships the 10.0.11 runtime, an environment gap, not a test issue). Fixes coverlet-coverage#2026 Signed-off-by: Eljees <3.14hell@gmail.com>
Contributor
Author
|
@dotnet-policy-service agree |
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Collaborator
|
Thank you for this PR. |
Bertk
approved these changes
Sep 22, 2026
Bertk
approved these changes
Sep 22, 2026
This was referenced Sep 27, 2026
This was referenced Sep 30, 2026
Open
Open
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
TryWithCustomResolverOnDotNetCoreinCecilAssemblyResolveronly resolves assemblies bylooking them up in
DependencyContext.CompileLibraries(built from the instrumentedmodule's
*.deps.json). Starting with the .NET SDK 10.0.4xx feature band, transitivelyshared
Microsoft.Extensions.*assemblies (e.g.Microsoft.Extensions.Logging,referenced only via a transitive
FrameworkReferencetoMicrosoft.AspNetCore.App, notdirectly on the instrumented project) are no longer enumerated in
compileLibrariesatall.
When a method has a default parameter of such a shared-framework enum type, Cecil's
resolver misses it and throws
CecilAssemblyResolutionExceptionwhile instrumenting —and that failure silently drops the entire module out of the coverage report
(
coverage.cobertura.xmlends up with an empty<packages/>) even thoughdotnet testitself is green, with no diagnostic pointing at the real cause.
NetCoreSharedFrameworkResolveralready exists in the same file and can resolve theseassemblies directly from the shared-framework directory via
runtimeconfig.json, but itwas only ever consulted as a constructor fallback, never re-tried when the
compileLibrarieslookup specifically misses by name. This PR adds that fallback: on acompileLibrariesmiss, askNetCoreSharedFrameworkResolverdirectly before giving up.Testing
Verified against a live repro matching the reporter's stack trace
(
CecilAssemblyResolutionException→Mono.Cecil.MetadataBuilder.GetConstantType) ondotnet SDK 10.0.400/10.0.401 (the same feature band as the report).
Added
TestInstrument_NetstandardAwareAssemblyResolver_MissingFromCompileLibrariesFallsBackToSharedFramework,modeled on the neighboring
..._SiblingRuntimeConfigCanResolveSharedFrameworkAssemblytest: a module with no adjacent
.deps.jsonforces thecompileLibrarieslookup to miss,and the test asserts
System.Text.Jsonstill resolves viaNetCoreSharedFrameworkResolver.5/5 green on net10.0 (net8.0 leg not run in this environment — the SDK image only ships
the 10.0.11 runtime, an environment gap, not a test issue).
Fixes #2026