Skip to content

Commit 964fefd

Browse files
ivanpovazanjkotas
andauthored
[libs][mono] Prevent static constructor from referencing Internal.Runtime.Augments.DynamicDelegateAugments in build scenarios without linking (#90519)
Fixes #90494 --------- Co-authored-by: Jan Kotas <jkotas@microsoft.com>
1 parent 3f65957 commit 964fefd

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/libraries/System.Linq.Expressions/src/System/Dynamic/Utils/DelegateHelpers.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,21 @@ private static class DynamicDelegateLightup
2323
= CreateObjectArrayDelegateInternal();
2424

2525
private static Func<Type, Func<object?[], object?>, Delegate> CreateObjectArrayDelegateInternal()
26-
=> Type.GetType("Internal.Runtime.Augments.DynamicDelegateAugments")!
27-
.GetMethod("CreateObjectArrayDelegate")!
28-
.CreateDelegate<Func<Type, Func<object?[], object?>, Delegate>>();
26+
{
27+
// This is only supported by NativeAOT which always expects CanEmitObjectArrayDelegate to be false.
28+
// This check guards static constructor of trying to resolve 'Internal.Runtime.Augments.DynamicDelegateAugments'
29+
// on runtimes which do not support this private API.
30+
if (!CanEmitObjectArrayDelegate)
31+
{
32+
return Type.GetType("Internal.Runtime.Augments.DynamicDelegateAugments, System.Private.CoreLib", throwOnError: true)!
33+
.GetMethod("CreateObjectArrayDelegate")!
34+
.CreateDelegate<Func<Type, Func<object?[], object?>, Delegate>>();
35+
}
36+
else
37+
{
38+
return new Func<Type, Func<object?[], object?>, Delegate>((_x, _y) => throw new NotImplementedException());
39+
}
40+
}
2941
}
3042

3143
private static class ForceAllowDynamicCodeLightup

0 commit comments

Comments
 (0)