dotnet/aspnetcore · error · Error
Unknown transport: ${transport}.
Error message
Unknown transport: ${transport}. What it means
Thrown at HttpConnection.ts:541 in the default branch of _constructTransport's switch. The switch handles WebSockets, ServerSentEvents, and LongPolling; any other numeric value (or a corrupted HttpTransportType) falls through to default. In practice this should be unreachable with the published enum, but it guards against bad input.
Source
Thrown at src/SignalR/clients/ts/signalr/src/HttpConnection.ts:541
}
private _constructTransport(transport: HttpTransportType): ITransport {
switch (transport) {
case HttpTransportType.WebSockets:
if (!this._options.WebSocket) {
throw new Error("'WebSocket' is not supported in your environment.");
}
return new WebSocketTransport(this._httpClient, this._accessTokenFactory, this._logger, this._options.logMessageContent!,
this._options.WebSocket, this._options.headers || {});
case HttpTransportType.ServerSentEvents:
if (!this._options.EventSource) {
throw new Error("'EventSource' is not supported in your environment.");
}
return new ServerSentEventsTransport(this._httpClient, this._httpClient._accessToken, this._logger, this._options);
case HttpTransportType.LongPolling:
return new LongPollingTransport(this._httpClient, this._logger, this._options);
default:
throw new Error(`Unknown transport: ${transport}.`);
}
}
private _startTransport(url: string, transferFormat: TransferFormat): Promise<void> {
this.transport!.onreceive = this.onreceive;
if (this.features.reconnect) {
this.transport!.onclose = async (e) => {
let callStop = false;
if (this.features.reconnect) {
try {
this.features.disconnected();
await this.transport!.connect(url, transferFormat);
await this.features.resend();
} catch {
callStop = true;
}
} else {
this._stopConnection(e);View on GitHub (pinned to 294cab2f9b)
Solutions
- Use a single concrete HttpTransportType value (WebSockets, ServerSentEvents, LongPolling) rather than a bitwise combination.
- If you need 'auto', omit the transport option entirely and let negotiation select.
- Ensure you are not passing a string like "WebSockets" — pass the enum member.
Example fix
// before (wrong: bitwise combo)
withUrl(url, { transport: HttpTransportType.WebSockets | HttpTransportType.LongPolling })
// after (auto-select)
withUrl(url)
// or explicit single transport
withUrl(url, { transport: HttpTransportType.WebSockets }) Defensive patterns
Strategy: type-guard
Validate before calling
const VALID = [HttpTransportType.WebSockets, HttpTransportType.ServerSentEvents, HttpTransportType.LongPolling];
function assertSingleTransport(t) {
if (!VALID.includes(t)) throw new Error(`Invalid transport: ${t}. Use one of ${VALID.join(', ')}`);
}
assertSingleTransport(options.transport); Type guard
function isSingleValidTransport(t: unknown): t is HttpTransportType {
return t === HttpTransportType.WebSockets || t === HttpTransportType.ServerSentEvents || t === HttpTransportType.LongPolling;
} Try / catch
try { await conn.start(transferFormat); }
catch (e) {
if (/Unknown transport/.test(String(e))) {
delete options.transport; // let negotiation auto-select
return new HttpConnection(url, options).start(transferFormat);
}
throw e;
} Prevention
- Always use the HttpTransportType enum, never magic numbers.
- Never combine transport flags with bitwise OR for the 'transport' option.
- Omit the transport option entirely if you want auto-selection.
When it happens
Trigger: Passing a numeric transport value outside 1/2/4 (e.g. 3, 7, 0) via a cast or untyped JS; an enum that was renamed/reordered across versions; constructing a custom transport value with bitwise math that produces an invalid combo (e.g. WebSockets | ServerSentEvents = 3 is not a single transport).
Common situations: Calling `_constructTransport` directly in tests with a fabricated number; combining transport flags where only a single concrete transport is expected; a future version of the enum introducing a new value the old client doesn't handle.
Related errors
- Invalid message type.
- Unknown ${name} value: ${val}.
- The ComponentRenderMode field only exists on frames of type
- Invalid boolean value '${attributeValue}' for parameter '${p
- Invalid number value '${attributeValue}' for parameter '${pa
AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06).
Data as JSON: /api/errors/1d39ed5b4cc9bd5e.
Report an issue: GitHub.