Skip to content

System.Diagnostics.DiagnosticsHelper.CompareTags is wrong #119264

Closed

Description

@duke-bartholomew

Description

According to the API documentation, System.Diagnostics.DiagnosticsHelper.CompareTags takes 2 parameters. The first, a sorted tag-list, and the second any other tag-list (can be unsorted) and evaluate whether these tag-lists are equal or not.

Well, this is not entirely true.

When I pass in following parameters:

sortedTags = [ new("A", "a"), new("B", "b"), new("C", "c") ]
tags2 = [ new("A", "a"), new("C", "c"), new("B", "bbb") ]

the function returns True instead of False.

reason being(I guess) is following line:

if (compareResult < 0 || j == count - 1)

Here: compareResult < 0 implies sorting, and, as the function documentation sais, the second list does not need to be sorted.

Reproduction Steps

Can be reproduced with a simple unit-test:

        List<KeyValuePair<string, object>>        sortedTags = [ new("A", "a"), new("B", "b"), new("C", "c") ];
        IEnumerable<KeyValuePair<string, object>> tags2      = [ new("A", "a"), new("C", "c"), new("B", "bbb") ];
        
        DiagnosticsHelper.CompareTags(sortedTags, tags2).Should().BeFalse();

Expected behavior

Above mentioned unit-test should succeed.

Actual behavior

Above mentioned unit-test fails.

Regression?

No response

Known Workarounds

Only work-around here would be to make sure both input lists are sorted.

Configuration

No response

Other information

No response

Activity

  1. added
    untriaged
    on Sep 2, 2025
  2. added
    needs-area-label
    on Sep 2, 2025
  3. added and removed
    needs-area-label
    on Sep 2, 2025
  4. removed
    untriaged
    on Aug 11, 2026
  5. added this to the 11.0.0 milestone on Aug 11, 2026
  6. added a commit that references this issue on Aug 19, 2026
    261c78a
  7. locked and limited conversation to collaborators on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions