Fix VSTHRD010 code fix crash in async lambdas - #1671
Open
Andrew Arnott (AArnott) wants to merge 1 commit into
Open
Fix VSTHRD010 code fix crash in async lambdas#1671Andrew Arnott (AArnott) wants to merge 1 commit into
Andrew Arnott (AArnott) wants to merge 1 commit into
Conversation
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>
There was a problem hiding this comment.
🟢 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:
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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