Skip to content

Commit a1c550c

Browse files
[reflection] Initialize default ALC gchandle in GetLoadContext (#60399)
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 Co-authored-by: Aleksey Kliger <alklig@microsoft.com>
1 parent 8b0cf9c commit a1c550c

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/mono/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.Mono.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ internal static Assembly[] GetLoadedAssemblies()
8080
// We only support looking up load context for runtime assemblies.
8181
if (rtAsm != null)
8282
{
83+
var _ = Default; // ensure the default ALC is initialized.
8384
RuntimeAssembly runtimeAssembly = rtAsm;
8485
IntPtr ptrAssemblyLoadContext = GetLoadContextForAssembly(runtimeAssembly);
8586
loadContextForAssembly = GetAssemblyLoadContext(ptrAssemblyLoadContext);

0 commit comments

Comments
 (0)