Skip to content

Commit

Permalink
Prevent static constructor from referencing DynamicDelegateLightup pr…
Browse files Browse the repository at this point in the history
…ivate API in scenarios without app linking
  • Loading branch information
ivanpovazan committed Aug 14, 2023
1 parent 8984d9a commit 6f8b3e8
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,23 @@ internal static class DelegateHelpers
// with the Reflection.Emit statics below.
private static class DynamicDelegateLightup
{
public static Func<Type, Func<object?[], object?>, Delegate> CreateObjectArrayDelegate { get; }
= CreateObjectArrayDelegateInternal();
public static Func<Type, Func<object?[], object?>, Delegate> CreateObjectArrayDelegate
{
get
{
// CreateObjectArrayDelegateInternal is only supported with NativeAOT which always expects CanEmitObjectArrayDelegate to be false.
// Additionally, this check guards static constructor of trying to resolve 'Internal.Runtime.Augments.DynamicDelegateAugments'
// on runtimes which do not support this private API, which would otherwise cause TypeInitializationException.
if (!CanEmitObjectArrayDelegate)
{
return CreateObjectArrayDelegateInternal();
}
else
{
throw new System.NotImplementedException();
}
}
}

private static Func<Type, Func<object?[], object?>, Delegate> CreateObjectArrayDelegateInternal()
=> Type.GetType("Internal.Runtime.Augments.DynamicDelegateAugments")!
Expand Down

0 comments on commit 6f8b3e8

Please sign in to comment.