Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libs][mono] Prevent static constructor from referencing Internal.Runtime.Augments.DynamicDelegateAugments in build scenarios without linking #90519

Merged
merged 5 commits into from
Aug 14, 2023
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();
}
}
}
ivanpovazan marked this conversation as resolved.
Show resolved Hide resolved

private static Func<Type, Func<object?[], object?>, Delegate> CreateObjectArrayDelegateInternal()
=> Type.GetType("Internal.Runtime.Augments.DynamicDelegateAugments")!
ivanpovazan marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading