Skip to content

Exclude non-equivalent async alternatives from VSTHRD103 - #1665

Open
Andrew Arnott (AArnott) wants to merge 2 commits into
mainfrom
aarnott-configurable-async-suggestions
Open

Exclude non-equivalent async alternatives from VSTHRD103#1665
Andrew Arnott (AArnott) wants to merge 2 commits into
mainfrom
aarnott-configurable-async-suggestions

Conversation

@AArnott

Copy link
Copy Markdown
Member

VSTHRD103 assumes an Async-suffixed counterpart is generally preferable, but several framework APIs use the async variant for different semantics or specialized cases. This causes incorrect recommendations for synchronous assertions and Entity Framework Core change tracking APIs.

Changes

  • Ship package-provided AdditionalFile exclusions for xUnit Throws/ThrowsAny, NUnit Assert.That, and EF Core DbContext/DbSet<TEntity> Add/AddRange.
  • Keep the policy data-driven so projects and NuGet packages can extend the same exclusion file pattern for their own APIs.
  • Document the built-in exclusions and add regression coverage that confirms matching remains scoped to exact containing types.

The task-flow case in #1662 is intentionally not addressed here because it is being fixed separately through semantic analysis.

Validation

  • All 98 VSTHRD103 analyzer tests pass on net8.0.
  • The packed analyzer includes the exclusion file under buildTransitive/AdditionalFiles.

Fixes #1661
Fixes #1480

Ship default VSTHRD103 exclusions for xUnit assertions, NUnit assertions, and Entity Framework Core APIs whose async variants have different semantics or specialized use cases.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings August 27, 2026 22:00

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 refines VSTHRD103 (“Use async methods when in an async method”) to avoid recommending Async-suffixed alternatives that are known to be non-equivalent for several common framework APIs (notably xUnit assertions, NUnit assertions, and EF Core change tracking APIs). It does this via a package-shipped AdditionalFiles exclusion list while keeping the approach extensible through the existing filename-pattern mechanism.

Changes:

  • Add a buildTransitive AdditionalFiles exclusion list (vs-threading.SyncMethodsToExcludeFromVSTHRD103.frameworks.txt) covering xUnit, NUnit, and EF Core methods with non-equivalent async counterparts.
  • Add a regression test to ensure the known framework exclusions suppress diagnostics while similarly-named methods on other types still produce diagnostics.
  • Update analyzer documentation to describe the package-provided default exclusions.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs Adds regression coverage for the new built-in exclusion cases and verifies type scoping.
src/Microsoft.VisualStudio.Threading.Analyzers.CodeFixes/buildTransitive/AdditionalFiles/vs-threading.SyncMethodsToExcludeFromVSTHRD103.frameworks.txt Introduces the package-shipped default exclusion list for VSTHRD103.
docfx/analyzers/VSTHRD103.md Minor documentation formatting tweak in the analyzer page.
docfx/analyzers/configuration.md Documents the built-in exclusions and how to extend exclusions via AdditionalFiles.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docfx/analyzers/configuration.md
Document the optional suffix accepted for AdditionalFiles that contribute VSTHRD103 exclusions.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 27, 2026 22:05

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

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

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.

VSTHRD103 regression: recommends ThrowsAsync for synchronous xUnit assertions False Positive with VSTHRD103 and EF DbSet AddRange

2 participants