diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/OpenMethodResolver.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/OpenMethodResolver.cs index b4fffe59189370..b9a5b1353499f2 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/OpenMethodResolver.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/OpenMethodResolver.cs @@ -22,6 +22,9 @@ namespace Internal.Runtime.CompilerServices [ReflectionBlocked] public struct OpenMethodResolver : IEquatable { + // Lazy initialized to point to the type loader method when the first `GVMResolve` resolver is created + private static unsafe delegate* s_lazyGvmLookupForSlot; + public const short DispatchResolve = 0; public const short GVMResolve = 1; public const short OpenNonVirtualResolve = 2; @@ -52,6 +55,9 @@ public unsafe OpenMethodResolver(RuntimeTypeHandle declaringTypeOfSlot, RuntimeM _handle = handle; _readerGCHandle = readerGCHandle; _nonVirtualOpenInvokeCodePointer = IntPtr.Zero; + + if (s_lazyGvmLookupForSlot == null) + s_lazyGvmLookupForSlot = &TypeLoaderExports.GVMLookupForSlot; } public OpenMethodResolver(RuntimeTypeHandle declaringType, IntPtr codePointer, GCHandle readerGCHandle, int handle) @@ -151,7 +157,7 @@ private unsafe IntPtr ResolveMethod(object thisObject) } else if (_resolveType == GVMResolve) { - return TypeLoaderExports.GVMLookupForSlot(thisObject, GVMMethodHandle); + return s_lazyGvmLookupForSlot(thisObject, GVMMethodHandle); } else {