private static void InitializeExplicitModeCheck() { // GetIsInCooperativeGCModeFunctionPointer is conditionally included based on the runtime build configuration, // so we check for its existence and only do the explicit mode validation if it is available. Type marshalType = typeof(object).Assembly.GetType(typeof(System.Runtime.InteropServices.Marshal).FullName); MethodInfo getFunctionPtr = marshalType.GetMethod("GetIsInCooperativeGCModeFunctionPointer", BindingFlags.NonPublic | BindingFlags.Static); if (getFunctionPtr != null) { var isInCooperativeModeFunc = (delegate * unmanaged <int>)(IntPtr) getFunctionPtr.Invoke(null, null); SuppressGCTransitionNative.SetIsInCooperativeModeFunction(isInCooperativeModeFunc); ExplicitModeCheckEnabled = true; Console.WriteLine("Explicit GC mode check is enabled"); } }