Test for unloadable ALC frees file lock#120066
Merged
AaronRobinsonMSFT merged 7 commits intodotnet:mainfrom Sep 26, 2025
Merged
Test for unloadable ALC frees file lock#120066AaronRobinsonMSFT merged 7 commits intodotnet:mainfrom
AaronRobinsonMSFT merged 7 commits intodotnet:mainfrom
Conversation
Remove extra AddRef() to remove file lock of DLL.
Contributor
There was a problem hiding this comment.
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 |
Contributor
|
Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov |
jkotas
reviewed
Sep 24, 2025
jkotas
reviewed
Sep 24, 2025
src/tests/Loader/CollectibleAssemblies/AssemblyOnDisk/Program.cs
Outdated
Show resolved
Hide resolved
agocke
approved these changes
Sep 24, 2025
jkotas
reviewed
Sep 24, 2025
jkotas
reviewed
Sep 24, 2025
Member
Author
|
This needs to be ported to .NET 10. |
Member
|
Test failures look related |
Member
Author
|
/backport to release/10.0 |
Contributor
|
Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/18022983560 |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Remove extra
AddRef()to remove file lock on DLL.Fixes #119647