Description
In ManagedWebSocket, ThrowIfInvalidMessageType enforces that only Text and Binary are passed.
The issue is that the ArgumentException (resource string) reports that any invalid message type was "Close".
It should report the actual invalid value that was passed, which could be Close or any other WebSocketMessageType. This could be an arbitrary invalid value, e.g. 999.
It is true that the only 3 valid types are currently Text, Binary, and Close.
I don't believe it should be hard-coded to Close, because:
- It is possible that WebSocket will add new message types in the future. This is a tricky place to have to update.
- It is possible to pass an invalid value (e.g. 999) by parsing or casting. I did this intentionally to test my code on invalid inputs, but it is conceivable it could happen accidentally.
Reproduction Steps
await _webSocket.SendAsync(
buffer: buffer,
messageType: (WebSocketMessageType) 999,
endOfMessage: true,
cancellationToken: cancellationToken
);
Expected behavior
System.ArgumentException: The message type '999' is not allowed for the 'SendAsync' operation. Valid message types are: 'Binary, Text'. To close the WebSocket, use the 'CloseOutputAsync' operation instead. (Parameter 'messageType')
Actual behavior
System.ArgumentException: The message type 'Close' is not allowed for the 'SendAsync' operation. Valid message types are: 'Binary, Text'. To close the WebSocket, use the 'CloseOutputAsync' operation instead. (Parameter 'messageType')
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
Description
In ManagedWebSocket, ThrowIfInvalidMessageType enforces that only Text and Binary are passed.
The issue is that the ArgumentException (resource string) reports that any invalid message type was "Close".
It should report the actual invalid value that was passed, which could be Close or any other WebSocketMessageType. This could be an arbitrary invalid value, e.g. 999.
It is true that the only 3 valid types are currently Text, Binary, and Close.
I don't believe it should be hard-coded to Close, because:
Reproduction Steps
Expected behavior
Actual behavior
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response