From fbadd4f76d7758619542029d123b4bfe7f9be2ea Mon Sep 17 00:00:00 2001 From: vitek-karas <10670590+vitek-karas@users.noreply.github.com> Date: Wed, 24 Nov 2021 11:18:32 -0800 Subject: [PATCH] Suppress trim warning caused by recent attribute removal changes This fixes a new warning generated by trimming some apps which was introduced in #54056. The `ComVisibleAttribute` in this case is referenced, but if it's removed it doesn't change functionality in any way. --- .../ReflectTypeDescriptionProvider.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectTypeDescriptionProvider.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectTypeDescriptionProvider.cs index ef3cc90c16dbb0..2e7dc3253411b3 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectTypeDescriptionProvider.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectTypeDescriptionProvider.cs @@ -69,14 +69,23 @@ internal sealed partial class ReflectTypeDescriptionProvider : TypeDescriptionPr // These are attributes that, when we discover them on interfaces, we do // not merge them into the attribute set for a class. - private static readonly Type[] s_skipInterfaceAttributeList = new Type[] + private static readonly Type[] s_skipInterfaceAttributeList = InitializeSkipInterfaceAttributeList(); + + [UnconditionalSuppressMessage ("ReflectionAnalysis", "IL2045:AttributeRemoval", + Justification = "The ComVisibleAttribute is marked for removal and it's referenced here. Since this array" + + "contains only attributes which are going to be ignored, removing such attribute" + + "will not break the functionality in any way.")] + private static Type[] InitializeSkipInterfaceAttributeList() { + return new Type[] + { #if FEATURE_SKIP_INTERFACE - typeof(System.Runtime.InteropServices.GuidAttribute), - typeof(System.Runtime.InteropServices.InterfaceTypeAttribute) + typeof(System.Runtime.InteropServices.GuidAttribute), + typeof(System.Runtime.InteropServices.InterfaceTypeAttribute) #endif - typeof(System.Runtime.InteropServices.ComVisibleAttribute), - }; + typeof(System.Runtime.InteropServices.ComVisibleAttribute), + }; + } internal static Guid ExtenderProviderKey { get; } = Guid.NewGuid();