diff --git a/src/libraries/System.Linq.Expressions/src/System/Dynamic/Utils/DelegateHelpers.cs b/src/libraries/System.Linq.Expressions/src/System/Dynamic/Utils/DelegateHelpers.cs index a56b5f813adec..011322a2454ad 100644 --- a/src/libraries/System.Linq.Expressions/src/System/Dynamic/Utils/DelegateHelpers.cs +++ b/src/libraries/System.Linq.Expressions/src/System/Dynamic/Utils/DelegateHelpers.cs @@ -23,9 +23,21 @@ private static class DynamicDelegateLightup = CreateObjectArrayDelegateInternal(); private static Func, Delegate> CreateObjectArrayDelegateInternal() - => Type.GetType("Internal.Runtime.Augments.DynamicDelegateAugments")! - .GetMethod("CreateObjectArrayDelegate")! - .CreateDelegate, Delegate>>(); + { + // This is only supported by NativeAOT which always expects CanEmitObjectArrayDelegate to be false. + // This check guards static constructor of trying to resolve 'Internal.Runtime.Augments.DynamicDelegateAugments' + // on runtimes which do not support this private API. + if (!CanEmitObjectArrayDelegate) + { + return Type.GetType("Internal.Runtime.Augments.DynamicDelegateAugments, System.Private.CoreLib", throwOnError: true)! + .GetMethod("CreateObjectArrayDelegate")! + .CreateDelegate, Delegate>>(); + } + else + { + return new Func, Delegate>((_x, _y) => throw new NotImplementedException()); + } + } } private static class ForceAllowDynamicCodeLightup