Skip to content

Fix silently empty coverage for shared-framework assemblies missing from compileLibraries - #2032

Merged
Bertk merged 1 commit into
coverlet-coverage:masterfrom
Eljees:fix-2026-shared-framework-resolver-fallback
Sep 22, 2026
Merged

Bertk merged 1 commit into
coverlet-coverage:masterfrom
Eljees:fix-2026-shared-framework-resolver-fallback

Conversation

@Eljees

@Eljees Eljees commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

What

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 PR adds that fallback: on a
compileLibraries miss, ask NetCoreSharedFrameworkResolver directly before giving up.

Testing

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 #2026

…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>
@Eljees

Eljees commented Sep 19, 2026

Copy link
Copy Markdown
Contributor Author

@dotnet-policy-service agree

@Bertk

Bertk commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@Bertk Bertk added the regression software bug of before working feature label Sep 22, 2026
@Bertk

Bertk commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Thank you for this PR.

@Bertk
Bertk merged commit d212822 into coverlet-coverage:master Sep 22, 2026
11 checks passed
This was referenced Sep 27, 2026
This was referenced Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coverlet-core regression software bug of before working feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Shared-framework assemblies are unresolvable during instrumentation because they are absent from deps.json

2 participants