dotnet / dotnet/sdk

Error after "prefer IsEmpty over Count" refactoring when original code uses pattern matching syntax

Open
#52,348 2 comments 0 reactions 0 assignees View on GitHub
untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

_This issue has been moved from [a ticket on Developer Community](https://developercommunity.visualstudio.com/t/Error-after-prefer-IsEmpty-over-Count-/11017155)._

---
\[severity:It bothers me. A fix would be nice\]
Hi,

in the current version of VS 2026 18.1.0 there seems to be a little bug when trying to apply the “prefer IsEmpty over Count” refactoring on a ConcurrentDictionary. It seems that this is only an issue if the original code uses pattern matching syntax

```
if (test. Count is > 0) // ... but the refactoring works as expected for: if (test. Count > 0)

```

same for

```
if (test. Count is 0)
{
test. TryAdd("d", 2);
}

```

after refactoring its:

```
if (IsEmpty)
{
test. TryAdd("d", 2);
}

```

Please see the attached gif video.
[Incorrect\_IsEmpty\_Refactorying.gif](https://aka.ms/dc/file?name=Be7918b4bd4264bb8b0cf8c02c9afaaf0639014720258158916_Incorrect_IsEmpty_Refactorying.gif&tid=e7918b4bd4264bb8b0cf8c02c9afaaf0639014720258158916)

---
### Original Comments

#### Feedback Bot on 12/17/2025, 08:50 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.