Skip to content

[API Compat] AttributeDifference is reported when same attribute appears multiple times with different ctor args #7585

@safern

Description

@safern

Take the following values:

Left:

[UnsupportedOS("browser")]
public class Foo
{
}

Right:

[UnsupportedOS("browser")]
[UnsupportedOS("ios")]
public class Foo
{
}

We would get an error:

error : CannotChangeAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' on 'System.Net.Http.HttpClientHandler.Send(System.Net.Http.HttpRequestMessage, System.Threading.CancellationToken)' changed from '[UnsupportedOSPlatformAttribute("browser")]' in the contract to '[UnsupportedOSPlatformAttribute("browser")]' in the implementation.

There should be no error here.

The problem seems to be as we group attributes by constructor documentation ID, and then when comparing the groups, we noticed the right group has 2 entries and the left 1, and thus it is marked as changed:

var attrGroups = attributes.GroupBy(c => c.Constructor.DocId());

And we always use the first attribute on the group for the error string:

string contractKey = attributeComparer.GetKey(group[0].Attributes.First());
string implementationKey = attributeComparer.GetKey(group[1].Attributes.First());

cc: @ericstj @steveisok

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Infrastructure-librariesArea maintained by .NET libraries team: APICompat, AsmDiff, GenAPI, GenFacades, PkgProj, etchelp wanted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions