From 2da10f583b742354141420d7d6b16aa6d5ab89f6 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Thu, 17 Jun 2021 23:33:51 -0400 Subject: [PATCH] Special-case no attributes in GetCustomAttributeData --- .../src/System/Reflection/CustomAttribute.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs index 1b825f0dc952f..cf35de2462752 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs @@ -237,6 +237,10 @@ private static CustomAttributeType InitCustomAttributeType(RuntimeType parameter private static IList GetCustomAttributes(RuntimeModule module, int tkTarget) { CustomAttributeRecord[] records = GetCustomAttributeRecords(module, tkTarget); + if (records.Length == 0) + { + return Array.Empty(); + } CustomAttributeData[] customAttributes = new CustomAttributeData[records.Length]; for (int i = 0; i < records.Length; i++)