diff --git a/src/libraries/System.Runtime/tests/System/Type/TypeTests.Get.cs b/src/libraries/System.Runtime/tests/System/Type/TypeTests.Get.cs index 5f19479bc6211..124687962d0f0 100644 --- a/src/libraries/System.Runtime/tests/System/Type/TypeTests.Get.cs +++ b/src/libraries/System.Runtime/tests/System/Type/TypeTests.Get.cs @@ -91,6 +91,12 @@ public void GetInterface_MixedCaseAmbiguity_ThrowsAmbiguousMatchException() { Assert.Throws(() => typeof(ClassWithMixedCaseInterfaces).GetInterface("mixedinterface", ignoreCase: true)); } + + [Fact] + public void GetCustomAttributes_Interface() + { + Assert.True(typeof(ExampleWithAttribute).GetCustomAttributes(typeof(INameable), inherit: false)[0] is NameableAttribute); + } } public class ClassWithNoInterfaces { } @@ -116,6 +122,20 @@ public interface Interface1 { } public interface Interface2 { } public interface Interface3 { } } + + public interface INameable + { + string Name { get; } + } + + [AttributeUsage (AttributeTargets.All, AllowMultiple=true)] + public class NameableAttribute : Attribute, INameable + { + string INameable.Name => "Nameable"; + } + + [Nameable] + public class ExampleWithAttribute { } } public interface Interface1 { } diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs index 3fde27fb5335c..cc141613b5e11 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs @@ -140,7 +140,8 @@ internal static object[] GetCustomAttributes(ICustomAttributeProvider obj, Type throw new ArgumentNullException(nameof(obj)); if (attributeType == null) throw new ArgumentNullException(nameof(attributeType)); - if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute) && attributeType != typeof(CustomAttribute) && attributeType != typeof(object)) + if (!attributeType.IsSubclassOf(typeof(Attribute)) && !attributeType.IsInterface + && attributeType != typeof(Attribute) && attributeType != typeof(CustomAttribute) && attributeType != typeof(object)) throw new ArgumentException(SR.Argument_MustHaveAttributeBaseClass + " " + attributeType.FullName); if (attributeType == typeof(CustomAttribute))