Skip to content

Conversation

@AaronRobinsonMSFT
Copy link
Member

Remove extra AddRef() to remove file lock on DLL.

Fixes #119647

Remove extra AddRef() to remove file lock of DLL.
Copy link
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 fixes a file lock issue with unloadable AssemblyLoadContext by removing an unnecessary AddRef() call in the CoreCLR VM. The fix prevents loaded assemblies from holding file locks after their AssemblyLoadContext has been unloaded, which was causing the issue described in GitHub #119647.

Key changes:

  • Removes extra AddRef() call that was preventing proper cleanup of file handles
  • Moves assembly validation to occur during Assembly creation rather than DomainAssembly construction
  • Adds comprehensive test to verify file locks are properly released after ALC unload

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/tests/Loader/CollectibleAssemblies/AssemblyOnDisk/Program.cs New test that verifies file locks are released after unloading collectible AssemblyLoadContext
src/tests/Loader/CollectibleAssemblies/AssemblyOnDisk/AssemblyOnDisk.csproj Test project configuration with required isolation settings
src/coreclr/vm/domainassembly.cpp Removes unnecessary AddRef() call and moves validation logic
src/coreclr/vm/assembly.hpp Makes Assembly constructor private for better encapsulation
src/coreclr/vm/assembly.cpp Moves PEAssembly validation to Assembly::Create and updates CONTRACTL macros

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov
See info in area-owners.md if you want to be subscribed.

Copy link
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

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

@AaronRobinsonMSFT
Copy link
Member Author

This needs to be ported to .NET 10.

@agocke
Copy link
Member

agocke commented Sep 25, 2025

Test failures look related

@AaronRobinsonMSFT
Copy link
Member Author

/backport to release/10.0

@github-actions
Copy link
Contributor

Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/18022983560

@AaronRobinsonMSFT AaronRobinsonMSFT merged commit 7430c6d into dotnet:main Sep 26, 2025
104 checks passed
@AaronRobinsonMSFT AaronRobinsonMSFT deleted the runtime_119647 branch September 26, 2025 01:03
@github-actions github-actions bot locked and limited conversation to collaborators Oct 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in AssemblyLoadContext (net10-rc.1)

3 participants