diff --git a/src/Microsoft.DotNet.ApiCompat/src/Rules/Compat/AttributeDifference.cs b/src/Microsoft.DotNet.ApiCompat/src/Rules/Compat/AttributeDifference.cs index 8558803afd0..f3a5d13dab3 100644 --- a/src/Microsoft.DotNet.ApiCompat/src/Rules/Compat/AttributeDifference.cs +++ b/src/Microsoft.DotNet.ApiCompat/src/Rules/Compat/AttributeDifference.cs @@ -83,7 +83,7 @@ public override DifferenceType Diff(IDifferences differences, ITypeDefinitionMem if (implMethod == null || contractMethod == null) return DifferenceType.Unknown; - bool changed = CheckAttributeDifferences(differences, implMethod, implMethod.Attributes, implMethod.Attributes); + bool changed = CheckAttributeDifferences(differences, implMethod, implMethod.Attributes, contractMethod.Attributes); IParameterDefinition[] method1Params = implMethod.Parameters.ToArray(); IParameterDefinition[] method2Params = contractMethod.Parameters.ToArray(); diff --git a/src/Microsoft.DotNet.ApiCompat/tests/AttributeDifferenceTests.cs b/src/Microsoft.DotNet.ApiCompat/tests/AttributeDifferenceTests.cs index 67019760c4b..b5d0f5d4c75 100644 --- a/src/Microsoft.DotNet.ApiCompat/tests/AttributeDifferenceTests.cs +++ b/src/Microsoft.DotNet.ApiCompat/tests/AttributeDifferenceTests.cs @@ -22,9 +22,10 @@ public void AttributeDifferenceIsFound() Assert.Contains("CannotRemoveAttribute : Attribute 'AttributeDifference.FooAttribute' exists on 'AttributeDifference.AttributeDifferenceClass1' in the implementation but not the contract.", runOutput); Assert.Contains("CannotRemoveAttribute : Attribute 'System.ComponentModel.DefaultValueAttribute' exists on generic param 'T' on member 'AttributeDifference.AttributeDifferenceClass1.GenericMethodWithAttribute()' in the implementation but not the contract.", runOutput); Assert.Contains("CannotRemoveAttribute : Attribute 'System.ComponentModel.DefaultValueAttribute' exists on generic param 'T' on member 'AttributeDifference.AttributeDifferenceClass1.GenericMethodWithAttribute()' in the implementation but not the contract.", runOutput); + Assert.Contains("CannotRemoveAttribute : Attribute 'AttributeDifference.FooAttribute' exists on 'AttributeDifference.AttributeDifferenceClass1.MethodWithAttribute()' in the implementation but not the contract.", runOutput); Assert.Contains("CannotRemoveAttribute : Attribute 'AttributeDifference.FooAttribute' exists on parameter 'myParameter' on member 'AttributeDifference.AttributeDifferenceClass1.MethodWithAttribute(System.String, System.Object)' in the implementation but not the contract.", runOutput); Assert.Contains("CannotRemoveAttribute : Attribute 'System.ComponentModel.DefaultValueAttribute' exists on generic param 'TOne' on member 'AttributeDifference.AttributeDifferenceGenericCLass' in the implementation but not the contract.", runOutput); - Assert.Contains("Total Issues: 5", runOutput); + Assert.Contains("Total Issues: 6", runOutput); } [Fact] diff --git a/src/Microsoft.DotNet.ApiCompat/tests/TestProjects/AttributeDifference/Contract/AttributeDifference.cs b/src/Microsoft.DotNet.ApiCompat/tests/TestProjects/AttributeDifference/Contract/AttributeDifference.cs index 11a807074ab..1344760bc70 100644 --- a/src/Microsoft.DotNet.ApiCompat/tests/TestProjects/AttributeDifference/Contract/AttributeDifference.cs +++ b/src/Microsoft.DotNet.ApiCompat/tests/TestProjects/AttributeDifference/Contract/AttributeDifference.cs @@ -10,6 +10,7 @@ public class AttributeDifferenceClass1 { public string MethodWithAttribute(string myParameter, [DefaultValue("myObject")] object myObject) => throw null; public T GenericMethodWithAttribute() => throw null; + public void MethodWithAttribute() { } } public class AttributeDifferenceGenericCLass { diff --git a/src/Microsoft.DotNet.ApiCompat/tests/TestProjects/AttributeDifference/Implementation/AttributeDifferenceClass1.cs b/src/Microsoft.DotNet.ApiCompat/tests/TestProjects/AttributeDifference/Implementation/AttributeDifferenceClass1.cs index c34b0c62efe..2e9020dd8f1 100644 --- a/src/Microsoft.DotNet.ApiCompat/tests/TestProjects/AttributeDifference/Implementation/AttributeDifferenceClass1.cs +++ b/src/Microsoft.DotNet.ApiCompat/tests/TestProjects/AttributeDifference/Implementation/AttributeDifferenceClass1.cs @@ -13,6 +13,8 @@ public class AttributeDifferenceClass1 { public string MethodWithAttribute([Foo] string myParameter, [DefaultValue("myObject")] object myObject) => myParameter; public T GenericMethodWithAttribute<[DefaultValue("T")] T>() => default(T); + [Foo] + public void MethodWithAttribute() { } } public class AttributeDifferenceGenericCLass<[DefaultValue("TOne")] TOne, [DefaultValue("TTwo")] TTwo>