diff --git a/src/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs b/src/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs index 50015dd595fc..0ebedf078570 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs @@ -1616,7 +1616,15 @@ private static unsafe bool FilterCustomAttributeRecord( if (ctorHasParameters) { // Resolve method ctor token found in decorated decoratedModule scope - ctor = decoratedModule.ResolveMethod(caRecord.tkCtor, attributeType.GenericTypeArguments, null).MethodHandle.GetMethodInfo(); + // See https://github.com/dotnet/coreclr/issues/21456 for why we fast-path non-generics here (fewer allocations) + if (attributeType.IsGenericType) + { + ctor = decoratedModule.ResolveMethod(caRecord.tkCtor, attributeType.GenericTypeArguments, null).MethodHandle.GetMethodInfo(); + } + else + { + ctor = ModuleHandle.ResolveMethodHandleInternal(decoratedModule.GetNativeHandle(), caRecord.tkCtor); + } } else {