Repository navigation
Reduce VSTHRD117 severity for default initializers - #1658
Merged
Andrew Arnott (AArnott) merged 2 commits intoAug 26, 2026
Merged
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 72e7451d-7612-42b6-bf1d-961d53b6c2f3
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 72e7451d-7612-42b6-bf1d-961d53b6c2f3
There was a problem hiding this comment.
Pull request overview
This PR updates the VSTHRD117 analyzer so that redundant inline initializers of [ThreadStatic] fields/backing fields that assign a semantic default value are reported as Info rather than Warning, while keeping non-default inline initializers and type-initializer (static ctor) assignments at Warning severity.
Changes:
- Adjust VSTHRD117 reporting for field/property inline initializers to emit
Infowhen the initializer is a semantic default (null,default, numeric zero,false,'\0', etc.). - Expand C# and Visual Basic tests to validate both
InfoandWarningseverities for inline initializers. - Update the VSTHRD117 documentation to describe the new severity distinction and recommended fixes.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/Microsoft.VisualStudio.Threading.Analyzers.Tests/ThreadStaticAnalyzerTests.cs | Updates/expands analyzer tests to assert per-case Info vs Warning severity for inline initializers in C# and VB. |
| src/Microsoft.VisualStudio.Threading.Analyzers/ThreadStaticAnalyzer.cs | Implements semantic default-value recognition for inline initializers and reports VSTHRD117 as Info for default initializers. |
| docfx/analyzers/VSTHRD117.md | Documents the new severity behavior and clarifies the “Solution” guidance for default vs non-default initializers. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Sandy Armstrong (sandyarmstrong)
approved these changes
Aug 26, 2026
Andrew Arnott (AArnott)
deleted the
aarnott-threadstatic-default-severity
branch
August 26, 2026 16:41
This was referenced Oct 26, 2026
Merged
Open
Closed
Bump the dev-minor-patch group with 16 updates
actions-marketplace-validations/macalbert_envilder#47
Open
Open
Open
Open
This was referenced Oct 27, 2026
Open
Bump Microsoft.VisualStudio.Threading.Analyzers from 17.14.15 to 18.12.1
tomokuni/ZenHanConverter#19
Closed
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.
Explicitly initializing a
[ThreadStatic]field to its type's default value is redundant, but it does not create inconsistent values across threads. Report these inline initializers as informational instead of warning-level diagnostics.The analyzer now recognizes semantic default values such as
null,default, numeric zero,false, and\0for fields and auto-property backing fields. Non-default initializers and static-constructor assignments remain warnings. C# and Visual Basic tests cover both severity paths, and the VSTHRD117 documentation explains the distinction.Validation
dotnet test --project .\test\Microsoft.VisualStudio.Threading.Analyzers.Tests\Microsoft.VisualStudio.Threading.Analyzers.Tests.csproj -c Release -- --filter-class ThreadStaticAnalyzerTests --filter-not-trait "FailsInCloudTest=true"