LoaderAllocator selection logic for a generic type instance does not account for a LoaderAllocator of type itself #111611
Labels
area-TypeSystem-coreclr
in-pr
There is an active PR which will close this issue when it is merged
untriaged
New issue has not been triaged by the area owner
Description
ClassLoader::ComputeLoaderModuleWorker
uses a LoaderAllocator creation number to determine the latest LoaderAllocator to place a class in. However the method does not account the number of the type definition itself when calculating the latest number and this can lead into a situation when the generic instance is put into an older LoaderAllocator.E.g. if we have type
ClassA
from AssemblyLoadContextA
with number 2 and typeClassB
from AssemblyLoadContextB
with number 5 the resulting loader allocator for the typeClassB
would correspond to AssemblyLoadContextA
with creation number 2. IfClassB
contains a static, such static would be then placed under the LoaderAllocatorA
, preventing AssemblyLoadContextB
from unloading unlessA
is unloaded.Reproduction Steps
Assembly A
Assembly B
A.dll
into a collectible AssemblyLoadContextA
.B.dll
into a collectible AssemblyLoadContextB
.ClassB<ClassA>
.B
.Expected behavior
AssemblyLoadContext
B
is unloaded successfullyActual behavior
AssemblyLoadContext
B
is not unloadedRegression?
No
Known Workarounds
No response
Configuration
No response
Other information
The following change seem to fix the issue - Unity-Technologies#279
The text was updated successfully, but these errors were encountered: