Skip to content

Commit

Permalink
[libs][mono] Prevent static constructor from referencing `Internal.Ru…
Browse files Browse the repository at this point in the history
…ntime.Augments.DynamicDelegateAugments` in build scenarios without linking (#90519)

Fixes #90494

---------

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
  • Loading branch information
ivanpovazan and jkotas committed Aug 14, 2023
1 parent 3f65957 commit 964fefd
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,21 @@ private static class DynamicDelegateLightup
= CreateObjectArrayDelegateInternal();

private static Func<Type, Func<object?[], object?>, Delegate> CreateObjectArrayDelegateInternal()
=> Type.GetType("Internal.Runtime.Augments.DynamicDelegateAugments")!
.GetMethod("CreateObjectArrayDelegate")!
.CreateDelegate<Func<Type, Func<object?[], object?>, 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<Func<Type, Func<object?[], object?>, Delegate>>();
}
else
{
return new Func<Type, Func<object?[], object?>, Delegate>((_x, _y) => throw new NotImplementedException());
}
}
}

private static class ForceAllowDynamicCodeLightup
Expand Down

0 comments on commit 964fefd

Please sign in to comment.