Skip to content

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

Open
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-invalid-message-type-reporting
Open

ManagedWebSocket: report actual messageType in invalid-type ArgumentException#129069
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-invalid-message-type-reporting

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 6, 2026

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);

…Exception

Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
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
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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.

Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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'

3 participants