Skip to content

Fix AssemblyChecker dependency resolution - #134297

Closed
steveisok wants to merge 1 commit into
mainfrom
steveisok-fix-assemblychecker-resolution
Closed

steveisok wants to merge 1 commit into
mainfrom
steveisok-fix-assemblychecker-resolution

Conversation

@steveisok

Copy link
Copy Markdown
Member

Description

AssemblyChecker uses MetadataLoadContext to inspect assembly attributes without retaining file locks. Its resolver only searched the runtime directory, causing inspection to fail when a custom attribute referenced an assembly located beside the inspected assembly.

Update the resolver to:

  • Probe the inspected assembly's directory first.
  • Fall back to the runtime directory for framework dependencies.
  • Create a resolver for each inspected assembly.

This prevents repeated FileNotFoundException crashes and the resulting crash dumps that could exhaust CI worker disk space.

Test coverage

Added an AssemblyChecker.Tests regression test with an assembly-level attribute defined in an adjacent assembly. The test fails with the previous implementation and passes with the updated resolver.

Validated with:

  • The focused regression test in Debug and Checked configurations.
  • The complete clr.toolstests subset.

Resolves #134296

Note

This pull request description was generated with GitHub Copilot.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/crossgen-contrib
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

AssemblyChecker.Tests lacks a test-framework reference, preventing the registered test project from compiling.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

Updates AssemblyChecker dependency resolution to find adjacent assemblies during metadata inspection, with regression coverage.

Changes:

  • Adds per-assembly probing with runtime fallback.
  • Adds external-attribute test fixtures and regression coverage.
  • Registers the tests in clr.toolstests.
File Summary
src/​coreclr/​tools/​AssemblyChecker/​AssemblyInspector.cs Adds adjacent-directory dependency resolution.
src/​coreclr/​tools/​AssemblyChecker/​AssemblyChecker.csproj Grants test access to internals.
src/​coreclr/​tools/​AssemblyChecker.Tests/​TestAssets/​ExternalAttribute/​ReferencedAssemblyAttribute.cs Defines the external attribute dependency.
src/​coreclr/​tools/​AssemblyChecker.Tests/​TestAssets/​ExternalAttribute/​ExternalAttribute.csproj Configures the external-attribute fixture.
src/​coreclr/​tools/​AssemblyChecker.Tests/​TestAssets/​AssemblyWithExternalAttribute/​Marker.cs Defines the assembly-level attribute usage.
src/​coreclr/​tools/​AssemblyChecker.Tests/​TestAssets/​AssemblyWithExternalAttribute/​AssemblyWithExternalAttribute.csproj Configures the assembly test fixture.
src/​coreclr/​tools/​AssemblyChecker.Tests/​AssemblyInspectorTests.cs Tests adjacent attribute resolution.
src/​coreclr/​tools/​AssemblyChecker.Tests/​AssemblyChecker.Tests.csproj Defines the regression test project.
eng/​Subsets.props Includes the tests in clr.toolstests.

Comment on lines +9 to +12
<ItemGroup>
<ProjectReference Include="../AssemblyChecker/AssemblyChecker.csproj" />
<ProjectReference Include="TestAssets/AssemblyWithExternalAttribute/AssemblyWithExternalAttribute.csproj" />
</ItemGroup>
@jkotas

jkotas commented Sep 20, 2026

Copy link
Copy Markdown
Member

#133622 is a better way to fix this. There is no reason for AssemblyChecker to resolve dependencies in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test failure: Interop Work Item throws System.IO.FileNotFoundException

3 participants