Skip to content

Commit

Permalink
[reflection] Initialize default ALC gchandle in GetLoadContext (#60350)
Browse files Browse the repository at this point in the history
If we try to get the ALC of an assembly from the default context before the
managed default ALC object has been created, the native gchandle has a null
target.
Ensure it is not null by explicitly referencing the Default ALC.

Fixes #60348
  • Loading branch information
lambdageek committed Oct 14, 2021
1 parent 92bfaea commit 3e98517
Showing 1 changed file with 1 addition and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ internal static Assembly[] GetLoadedAssemblies()
// We only support looking up load context for runtime assemblies.
if (rtAsm != null)
{
var _ = Default; // ensure the default ALC is initialized.
RuntimeAssembly runtimeAssembly = rtAsm;
IntPtr ptrAssemblyLoadContext = GetLoadContextForAssembly(runtimeAssembly);
loadContextForAssembly = GetAssemblyLoadContext(ptrAssemblyLoadContext);
Expand Down

0 comments on commit 3e98517

Please sign in to comment.