Skip to content

Exclude MemoryStream operations from VSTHRD103 - #1702

Open
Andrew Arnott (AArnott) with Copilot wants to merge 8 commits into
mainfrom
copilot/fix-vsthrd103-memorystream-operations
Open

Andrew Arnott (AArnott) with Copilot wants to merge 8 commits into
mainfrom
copilot/fix-vsthrd103-memorystream-operations

Conversation

Copilot AI commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

VSTHRD103 recommends async alternatives for synchronous MemoryStream operations, where accessing in-memory data needs no async machinery. These APIs should be exempt by default rather than requiring per-project configuration.

  • Packaged defaults: Exclude Read, Write, Flush, CopyTo, and Dispose.
  • Receiver matching: Match instance-method exclusions against the receiver’s static type as well as the declaring type, covering inherited overloads without suppressing diagnostics on Stream-typed receivers.
  • Coverage and documentation: Add regression coverage for overloads, conditional access, and Stream-typed calls. Document the defaults and note that CopyTo destinations may still perform blocking I/O.
static async Task<int> ReadAsync(MemoryStream stream, byte[] buffer)
{
    await Task.Yield();
    return stream.Read(buffer, 0, buffer.Length); // No VSTHRD103
}

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI and others added 2 commits October 13, 2026 16:50
Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix VSTHRD103 reporting on MemoryStream operations Exclude MemoryStream operations from VSTHRD103 Oct 13, 2026
@AArnott
Andrew Arnott (AArnott) marked this pull request as ready for review November 20, 2026 22:59
Copilot AI balanced review requested due to automatic review settings November 20, 2026 23:00
@AArnott

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

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.

🟡 Changes recommended

Receiver-type exclusions are bypassed for known blocking methods, and the new Read test passes without exercising the exclusion because its enclosing method is named ReadAsync.

2 open issues
What changed in this PR

Adds built-in VSTHRD103 exemptions for synchronous MemoryStream operations, addressing #1699 while preserving diagnostics for Stream-typed receivers.

Changes:

  • Exclude Read, Write, Flush, CopyTo, and Dispose by default.
  • Extend instance-method exclusion matching to the receiver’s static type.
  • Add regression coverage and document the defaults, including the risk of blocking I/O at CopyTo destinations.
File Description
test/​Microsoft.VisualStudio.Threading.Analyzers.Tests/​VSTHRD103UseAsyncOptionAnalyzerTests.cs Adds coverage for overloads, conditional access, and Stream-typed calls.
src/​Microsoft.VisualStudio.Threading.Analyzers.CSharp/​VSTHRD103UseAsyncOptionAnalyzer.cs Adds receiver-type matching to exclusion checks.
src/​Microsoft.VisualStudio.Threading.Analyzers.CodeFixes/​buildTransitive/​AdditionalFiles/​vs-threading.SyncMethodsToExcludeFromVSTHRD103.frameworks.txt Packages the five default MemoryStream exclusions.
docfx/​analyzers/​VSTHRD103.md Explains the exemption and the CopyTo destination caveat.
docfx/​analyzers/​configuration.md Documents receiver matching and lists the new defaults.

Review effort: Balanced

Copilot AI commented Nov 20, 2026

Copy link
Copy Markdown

One or more custom setup steps configured for this repository failed during this Copilot code review run:

Authenticate to Azure with GitHub OIDC

Setup steps run before each review. If the review above is missing context, or no review was posted at all, the failing step above may be the cause. See the workflow run for failure details, fix your setup steps configuration, and re-request a review.

Note

You can configure setup steps for Copilot code review separately from Copilot cloud agent with a copilot-code-review.yml file. Read the docs for details.

@AArnott

Copy link
Copy Markdown
Member

Copilot respond to the code review feedback.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 20, 2026 23:25

Copilot AI commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Copilot respond to the code review feedback.

Addressed both review findings in e216f86. The targeted tests could not run because required NuGet packages failed to download from the Azure DevOps feeds.

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.

🟡 Changes recommended

The added test passes through the existing declaring-type check, so it does not protect the new receiver-type matching against regression and should exclude Task`1 instead.

1 open issue
2 resolved since last review

Review effort: Balanced

Copilot AI commented Nov 20, 2026

Copy link
Copy Markdown

One or more custom setup steps configured for this repository failed during this Copilot code review run:

Authenticate to Azure with GitHub OIDC

Setup steps run before each review. If the review above is missing context, or no review was posted at all, the failing step above may be the cause. See the workflow run for failure details, fix your setup steps configuration, and re-request a review.

Note

You can configure setup steps for Copilot code review separately from Copilot cloud agent with a copilot-code-review.yml file. Read the docs for details.

@AArnott

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

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

No active review issues are identified for the VSTHRD103 MemoryStream exclusion changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@AArnott

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

…-memorystream-operations

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 02:15
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

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

No active review issues block approval of the MemoryStream exclusion changes.

No open issues 🎉

Review effort: Balanced

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

No active review issues are reported for the in-memory stream exclusions and receiver-type matching changes.

No open issues 🎉

Review effort: Balanced

This branch has not been deployed

No deployments
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 should not report on MemoryStream operations

5 participants