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 @@ -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.
ivanpovazan marked this conversation as resolved.
Show resolved Hide resolved
// 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
Loading