Skip to content

Operations Which Have a Default StringComparer Should Strongly Suggest Explicitly Specifying the StringComparer #47775

Closed

Description

@aolszowka

Brief description:
Background on the issue here: #43802

The default string comparer can have different results based on the running environment (such as platform or culture). Here's an earlier instance of this expected behavior, specifically about Windows vs. macOS/Linux and the ICU library: dotnet/roslyn#20109.

It's generally best practice to avoid using string comparison defaults so you don't run into this kind of issue: https://docs.microsoft.com/en-us/dotnet/standard/base-types/best-practices-strings#specifying-string-comparisons-explicitly

This is a real gotcha in my mind for anyone new to the ecosystem.

Historically I have used this excellent Roslyn Analyzer https://github.com/meziantou/Meziantou.Analyzer to catch similar issues, however I feel this is important enough to be something that should be out of the box. I have filed a request with that project as well here meziantou/Meziantou.Analyzer#196.

Languages applicable:
All Languages

Code example that the analyzer should report:
SortedDictionary<string, int> sortedDictionary = new SortedDictionary<string, int>();

Is one such example that show throw a warning to indicate that you have not specified the StringComparer

The linked repository in the issue (https://github.com/aolszowka/DotNetCoreSortedDictionaryCrossPlatform) shows what happens cross platform when this is not followed.

Activity

  1. ghost added
    untriaged
    on Feb 2, 2021
  2. removed
    untriaged
    on Jul 12, 2021
  3. added this to the Future milestone on Jul 12, 2021
  4. dotnet-policy-service commented on Jan 11, 2026

    @dotnet-policy-service
    Contributor

    Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.

    This process is part of our issue cleanup automation.

  5. added
    backlog-cleanup-candidate
    on Jan 11, 2026
  6. dotnet-policy-service commented on Jan 25, 2026

    @dotnet-policy-service
    Contributor

    This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.

  7. removed this from the Future milestone on Jan 25, 2026
  8. locked and limited conversation to collaborators on Feb 25, 2026
  9. removed
    backlog-cleanup-candidate
    on Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions