Skip to content

Improve StringBuilder.ToString() exception message for inconsistent state - #132483

Open
aw0lid wants to merge 1 commit into
dotnet:mainfrom
aw0lid:fix/stringbuilder-tostring-exception-message
Open

Improve StringBuilder.ToString() exception message for inconsistent state#132483
aw0lid wants to merge 1 commit into
dotnet:mainfrom
aw0lid:fix/stringbuilder-tostring-exception-message

Conversation

@aw0lid

@aw0lid aw0lid commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Fixes #131674.

Summary

When internal chunk boundaries are inconsistent (typically due to concurrent modification), StringBuilder.ToString() previously threw an ArgumentOutOfRangeException with chunkLength as the parameter name.

While the exception type is kept for compatibility, the message and parameter name are corrected. This PR updates the exception to use a clear, dedicated resource string indicating internal state corruption rather than a fictitious method parameter.

Changes

  • Updated bounds validation in StringBuilder.ToString() to throw ArgumentOutOfRangeException with null parameter name and a proper descriptive message (SR.InvalidOperation_ConcurrentOperationsNotSupported).

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Aug 18, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

@aw0lid
aw0lid marked this pull request as ready for review August 18, 2026 20:23
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Comment thread src/libraries/System.Private.CoreLib/src/Resources/Strings.resx Outdated
@aw0lid
aw0lid force-pushed the fix/stringbuilder-tostring-exception-message branch from 78ec096 to aad46c3 Compare August 18, 2026 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Runtime 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.

StringBuilder.ToString() throws misleading ArgumentOutOfRangeException for internal chunk inconsistency

2 participants