Skip to content

Fix VSTHRD010 code fix crash in async lambdas - #1671

Open
Andrew Arnott (AArnott) wants to merge 1 commit into
mainfrom
aarnott-fix-vsthrd010-lambdas
Open

Fix VSTHRD010 code fix crash in async lambdas#1671
Andrew Arnott (AArnott) wants to merge 1 commit into
mainfrom
aarnott-fix-vsthrd010-lambdas

Conversation

@AArnott

Copy link
Copy Markdown
Member

VSTHRD010 diagnostics in async lambdas can carry an empty list of configured main-thread switching methods. The code fix currently treats that empty property as a method name and throws during symbol lookup.

Filter blank switching-method entries before lookup so no code action is offered when no valid method is configured. Add regression coverage for the crash and for the already-correct main-thread switch behavior from #1670.

Fixes #1669

Filter empty main-thread switching method entries before symbol lookup so requesting a code fix in an async lambda does not throw.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 1, 2026 23:52

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.

🟢 Approval recommended

The changes directly address the reported crash condition with a minimal, safe guard and add targeted regression coverage for both the crash and the related analyzer behavior.

Pull request overview

This PR hardens the VSTHRD010 code fix against analyzer diagnostics that carry an empty configured main-thread switching-method list (notably in async anonymous methods/lambdas), preventing a crash during symbol lookup and ensuring no code action is offered when no valid switching method is configured.

Changes:

  • Filter out blank/whitespace switching-method entries before attempting method-group lookup in the VSTHRD010 code fix.
  • Add regression coverage for (a) the async anonymous-method “already on main thread” scenario (from #1670) and (b) the “no switching methods configured” crash case (from #1669).
File summaries
File Description
test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD010MainThreadUsageAnalyzerTests.cs Adds regression tests covering async anonymous-method main-thread switching behavior and ensuring the code fix does not crash (and offers no action) when switching methods are unconfigured.
src/Microsoft.VisualStudio.Threading.Analyzers.CodeFixes/VSTHRD010MainThreadUsageCodeFix.cs Filters blank switching-method options so symbol lookup is skipped when the configured list is empty.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

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

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.

VSTHRD010 code fix fails inside a lambda

2 participants