Skip to content

Fix VSTHRD200 misfiring on methods returning IAsyncEnumerator<T> - #1613

Merged
Andrew Arnott (AArnott) merged 2 commits into
mainfrom
copilot/fix-vsthread200-misfires
Jul 8, 2026
Merged

Andrew Arnott (AArnott) merged 2 commits into
mainfrom
copilot/fix-vsthread200-misfires

Conversation

Copilot AI commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

VSTHRD200 incorrectly treated IAsyncEnumerator<T> as a non-async return type, causing false "remove Async suffix" warnings and missing "add Async suffix" warnings for methods returning it.

Changes

  • Utils.cs — Extended IsAsyncCompatibleReturnType to recognize IAsyncEnumerator<T> (in addition to IAsyncEnumerable<T>) as an async-compatible return type. Both live in System.Collections.Generic so the check is a simple name OR condition on the existing namespace check.
  • VSTHRD200UseAsyncNamingConventionAnalyzerTests.cs — Added two test cases mirroring the existing IAsyncEnumerable<T> coverage: one confirming a warning is generated without the Async suffix, and one confirming no warning with the suffix.
// Before fix: no warning (should warn), and FooAsync would get a spurious "remove Async" warning
IAsyncEnumerator<int> Foo() => ...;

// After fix: VSTHRD200 correctly requires the Async suffix
IAsyncEnumerator<int> FooAsync() => ...;

… type

Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix VSTHRD200 mis-fires on async methods returning IAsyncEnumerator Fix VSTHRD200 misfiring on methods returning IAsyncEnumerator&lt;T&gt; Jul 8, 2026
@AArnott
Andrew Arnott (AArnott) marked this pull request as ready for review July 8, 2026 01:46
Copilot AI review requested due to automatic review settings July 8, 2026 01:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the VSTHRD200 async naming analyzer so that methods returning IAsyncEnumerator<T> are treated as “async-focused” return types, eliminating incorrect “remove Async suffix” suggestions and restoring the expected “add Async suffix” diagnostic behavior.

Changes:

  • Extend Utils.IsAsyncCompatibleReturnType to recognize System.Collections.Generic.IAsyncEnumerator<T> alongside IAsyncEnumerable<T>.
  • Add VSTHRD200 test coverage to ensure methods returning IAsyncEnumerator<T> require the Async suffix and don’t warn when the suffix is present.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Microsoft.VisualStudio.Threading.Analyzers/Utils.cs Updates async-focused return type detection to include IAsyncEnumerator<T> by name under System.Collections.Generic.
test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD200UseAsyncNamingConventionAnalyzerTests.cs Adds two new tests validating VSTHRD200 diagnostics for IAsyncEnumerator<T> return types (with and without Async suffix).

@AArnott Andrew Arnott (AArnott) changed the title Fix VSTHRD200 misfiring on methods returning IAsyncEnumerator&lt;T&gt; Fix VSTHRD200 misfiring on methods returning IAsyncEnumerator<T> Jul 8, 2026
@AArnott
Andrew Arnott (AArnott) merged commit f90eec8 into main Jul 8, 2026
10 checks passed
@AArnott
Andrew Arnott (AArnott) deleted the copilot/fix-vsthread200-misfires branch July 8, 2026 13:39
This was referenced Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VSTHRD200 mis-fires on methods that return IAsyncEnumerator<T>

5 participants