Skip to content

Document Expression.Block ReadOnlyCollection reuse#12754

Open
YNan-varamor wants to merge 1 commit into
dotnet:mainfrom
YNan-varamor:docs/expression-block-readonlycollection
Open

Document Expression.Block ReadOnlyCollection reuse#12754
YNan-varamor wants to merge 1 commit into
dotnet:mainfrom
YNan-varamor:docs/expression-block-readonlycollection

Conversation

@YNan-varamor

Copy link
Copy Markdown

Summary

  • document that Expression.Block overloads accepting IEnumerable can reuse a ReadOnlyCollection
  • warn callers not to mutate the underlying storage after creating the block
  • suggest taking a stable snapshot when the original source can change

Motivation

Addresses #12691. The runtime behavior discussed in dotnet/runtime#128813 is longstanding, so this adds the requested documentation warning rather than changing behavior.

Validation

  • git diff --check
  • parsed xml/System.Linq.Expressions/Expression.xml with PowerShell [xml]

Disclosure

Prepared with assistance from OpenAI Codex.

@github-actions github-actions Bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jun 17, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jun 17, 2026
@dotnet-policy-service dotnet-policy-service Bot removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jun 17, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @cston

@YNan-varamor YNan-varamor marked this pull request as ready for review June 23, 2026 04:42
@YNan-varamor YNan-varamor requested a review from 333fred as a code owner June 23, 2026 04:42
Copilot AI review requested due to automatic review settings June 23, 2026 04:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 updates the .NET API reference documentation for System.Linq.Expressions.Expression.Block to warn about a longstanding behavior where certain overloads can reuse caller-provided collections, which can lead to surprising results if the underlying storage is mutated after the block is created.

Changes:

  • Added remarks warning that Expression.Block overloads taking IEnumerable<Expression> might reuse a provided ReadOnlyCollection<Expression> instance.
  • Added guidance advising callers not to mutate underlying storage and to take a stable snapshot when the source can change.
  • Replaced placeholder remarks (“To be added.”) with markdown remarks content for additional overloads.

Comment on lines +2703 to +2710
<remarks>
<format type="text/markdown"><![CDATA[

## Remarks
If you pass a <xref:System.Collections.ObjectModel.ReadOnlyCollection%601> instance as the `expressions` argument, the returned <xref:System.Linq.Expressions.BlockExpression> might reuse that collection instead of copying it. Do not modify the collection's underlying storage after creating the block. If the source can be mutated, create a stable snapshot before passing it to this method.

]]></format>
</remarks>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YNan-varamor please address this comment. The other comments are bogus, but this is correct.

Comment thread xml/System.Linq.Expressions/Expression.xml
Comment thread xml/System.Linq.Expressions/Expression.xml
Comment thread xml/System.Linq.Expressions/Expression.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Linq.Expressions community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants