Fix LoaderAllocator computation for a generic type instance #279
+7
−1
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.
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 the 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 type ClassB would correspond to AssemblyLoadContextA
. IfClassB
contains a static, such static would be then placed under the LoaderAllocatorA
, preventing AssemblyLoadContextB
from unloading.The PR updates the
ComputeLoaderModuleWorker
logic to account for the LoaderAllocator of a defining type, so we use it if it has the latest creation number