Skip to content

Add tests for assembly resolution downgrading via extension mechanisms#118040

Merged
elinor-fung merged 7 commits intomainfrom
copilot/fix-84039
Aug 6, 2025
Merged

Add tests for assembly resolution downgrading via extension mechanisms#118040
elinor-fung merged 7 commits intomainfrom
copilot/fix-84039

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jul 24, 2025

This PR adds comprehensive tests to validate that assembly resolution extension mechanisms can successfully downgrade assembly version requests, while normal runtime resolution cannot.

cc @dotnet/appmodel @AaronRobinsonMSFT

What was missing

The .NET runtime supports assembly version downgrading (resolving a request for A, Version=3.0 with A, Version=1.0) but only through extension mechanisms:

  • AppDomain.AssemblyResolve event handler
  • AssemblyLoadContext.Resolving event handler
  • Custom AssemblyLoadContext.Load override

However, there were no tests specifically validating this downgrading behavior.

What this PR adds

New test assemblies:

  • System.Runtime.Loader.Test.AssemblyVersion1 - produces assembly with version 1.0.0

New test class AssemblyResolutionDowngradeTest with 4 test methods:

  1. AppDomainAssemblyResolve_CanDowngradeVersion - Validates that AppDomain.AssemblyResolve can resolve a version 3.0.0 request with version 1.0.0 assembly
  2. AssemblyLoadContextResolving_CanDowngradeVersion - Validates that AssemblyLoadContext.Resolving event can perform the same downgrade
  3. CustomAssemblyLoadContextLoad_CanDowngradeVersion - Validates that custom AssemblyLoadContext.Load override can perform downgrades
  4. NormalResolution_CannotDowngradeVersion - Validates baseline behavior that normal runtime resolution cannot downgrade versions

Test approach

Each test:

  • Requests assembly System.Runtime.Loader.Test.VersionDowngrade, Version=3.0.0.0
  • Extension mechanism returns the version 1.0.0 assembly instead
  • Verifies the runtime accepts the downgrade and returns the 1.0.0 assembly
  • Validates the returned assembly works correctly (can invoke methods, correct version reported)

The tests use RemoteExecutor to isolate assembly loading behavior and prevent interference between test runs.

Fixes #84039.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits July 24, 2025 22:12
Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Copilot AI changed the title [WIP] Add tests for downgrading assembly resolution via resolution extensions Add tests for assembly resolution downgrading via extension mechanisms Jul 24, 2025
Copilot AI requested a review from elinor-fung July 24, 2025 22:14
Comment thread src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs Outdated
…rivate

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Copilot AI requested a review from elinor-fung July 25, 2025 04:41
Comment thread src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs Outdated
Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Copilot AI requested a review from elinor-fung July 25, 2025 17:01
@elinor-fung elinor-fung marked this pull request as ready for review July 28, 2025 16:30
Copilot AI review requested due to automatic review settings July 28, 2025 16:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds comprehensive tests to validate that assembly resolution extension mechanisms can successfully downgrade assembly version requests from higher to lower versions, while normal runtime resolution cannot perform such downgrades.

Key changes:

  • Creates test infrastructure with two test assemblies having the same name but different versions (1.0.0 and 3.0.0)
  • Adds test methods validating downgrade behavior across three extension mechanisms: AppDomain.AssemblyResolve, AssemblyLoadContext.Resolving, and custom AssemblyLoadContext.Load override
  • Includes platform-specific testing for normal resolution behavior differences between CoreCLR and Mono

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
System.Runtime.Loader.Tests.csproj Adds the new test class and references to the version test assemblies as embedded resources
AssemblyResolutionDowngradeTest.cs Main test class with four test methods validating downgrade scenarios and helper classes
System.Runtime.Loader.Test.AssemblyVersion1.csproj Test assembly project configured for version 1.0.0 with shared assembly name
VersionTestClass.cs (Version1) Test class providing version identification methods for the 1.0.0 assembly
System.Runtime.Loader.Test.AssemblyVersion3.csproj Test assembly project configured for version 3.0.0 with shared assembly name
VersionTestClass.cs (Version3) Test class providing version identification methods for the 3.0.0 assembly

Comment thread src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs Outdated
Comment thread src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs Outdated
Comment thread src/libraries/System.Runtime.Loader/tests/AssemblyResolutionDowngradeTest.cs Outdated
Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Copilot AI requested a review from elinor-fung July 28, 2025 19:12
@elinor-fung elinor-fung merged commit 1722487 into main Aug 6, 2025
79 of 81 checks passed
@elinor-fung elinor-fung deleted the copilot/fix-84039 branch August 6, 2025 02:08
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for downgrading assembly resolution via resolution extensions

4 participants