Skip to content

ManagedWebSocket: report actual messageType in invalid-type ArgumentException - #129069

Merged
MihaZupan merged 3 commits into
mainfrom
copilot/fix-invalid-message-type-reporting
Jun 16, 2026
Merged

MihaZupan merged 3 commits into
mainfrom
copilot/fix-invalid-message-type-reporting

Conversation

Copilot AI commented Jun 6, 2026 •

Copy link
Copy Markdown
Contributor

ManagedWebSocket.ThrowIfInvalidMessageType hardcoded "Close" into the ArgumentException message regardless of the value supplied by the caller, so e.g. SendAsync(..., (WebSocketMessageType)999, ...) produced a misleading "The message type 'Close' is not allowed...".

  • Pass the actual messageType through to the SR.Format call (placeholder {0}) in src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/ManagedWebSocket.cs, replacing the hardcoded nameof(WebSocketMessageType.Close).
  • Mirrors what BrowserWebSocket.SendAsync already does, so behavior is now consistent across implementations and future-proof against new WebSocketMessageType values.
// Before: always "Close"
// After: "999" for (WebSocketMessageType)999, "Close" for WebSocketMessageType.Close, etc.
static void ThrowInvalidMessageType(WebSocketMessageType messageType, string? paramName) =>
    throw new ArgumentException(SR.Format(
        SR.net_WebSockets_Argument_InvalidMessageType,
        messageType, nameof(SendAsync), nameof(WebSocketMessageType.Binary),
        nameof(WebSocketMessageType.Text), nameof(CloseOutputAsync)),
        paramName);

Copilot AI requested review from Copilot and removed request for Copilot June 6, 2026 13:15
Copilot AI changed the title [WIP] Fix actual invalid input reporting in ThrowIfInvalidMessageType ManagedWebSocket: report actual messageType in invalid-type ArgumentException Jun 6, 2026
Copilot AI requested a review from MihaZupan June 6, 2026 13:16
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@MihaZupan MihaZupan added this to the 11.0.0 milestone Jun 6, 2026
@MihaZupan
MihaZupan marked this pull request as ready for review June 6, 2026 13:34
Copilot AI review requested due to automatic review settings June 6, 2026 13:34
@MihaZupan
MihaZupan enabled auto-merge (squash) June 6, 2026 13:34

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

Updates ManagedWebSocket.ThrowIfInvalidMessageType so the ArgumentException message reports the actual invalid WebSocketMessageType value provided by the caller (including undefined enum values), rather than always reporting "Close".

Changes:

  • Passes the messageType argument through to the SR.Format placeholder for the invalid-message-type exception.
  • Updates the local throw helper signature to accept messageType and propagate it into the formatted message.

auto-merge was automatically disabled June 6, 2026 14:15

Head branch was pushed to by a user without write access

Copilot AI requested a review from MihaZupan June 6, 2026 14:16
@MihaZupan
MihaZupan requested review from a team and removed request for a team June 8, 2026 20:54
@MihaZupan
MihaZupan merged commit 820be0c into main Jun 16, 2026
107 checks passed
@MihaZupan
MihaZupan deleted the copilot/fix-invalid-message-type-reporting branch June 16, 2026 07:40
@dotnet-milestone-bot dotnet-milestone-bot Bot modified the milestones: 11.0.0, 11.0-preview6 Jun 17, 2026
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
…xception (#129069)

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: MihaZupan <[email protected]>
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ManagedWebSocket: ThrowIfInvalidMessageType: ArgumentException should report actual invalid input, not assume all invalids are 'Close'

4 participants