dotnet/aspnetcore · error · Error
Expected data to be of type
Error message
Expected data to be of type ${typeof(this._buffer)} but was of type ${typeof(data)} What it means
Thrown by the send-loop's _bufferData helper when a new chunk's type does not match the type of data already buffered. The buffer is homogeneous — once you push a string you must keep pushing strings, and once you push an ArrayBuffer you must keep pushing ArrayBuffers. Mixing types breaks the framing contract with the underlying transport.
Solutions
- Pick one hub protocol per connection and stick to its transfer format (Text -> strings, Binary -> ArrayBuffer).
- Encode strings to ArrayBuffer (TextEncoder) only when using a binary protocol, and vice-versa.
- Do not reuse a connection across protocol changes; rebuild it with the desired protocol.
Example fix
// before - mixing types on one connection
conn.send("Method", "text");
conn.send("Method", new Uint8Array([1,2,3]));
// after - keep the buffer homogeneous for the chosen protocol
conn.send("Method", "text");
conn.send("Method", "more-text"); Defensive patterns
Strategy: type-guard
Validate before calling
function ensureHomogeneous(buffer: unknown[], next: string | ArrayBuffer): void {
if (buffer.length && typeof buffer[0] !== typeof next) {
throw new TypeError("Refusing to mix string and ArrayBuffer payloads");
}
} Type guard
function isStringPayload(p: unknown): p is string {
return typeof p === "string";
} Prevention
- Use a single hub protocol per connection (Text -> strings, Binary -> ArrayBuffer).
- Never switch protocols on a live connection.
- Encode payloads to match the negotiated transfer format.
When it happens
Trigger: Calling `connection.send(...)` / `hubConnection.send` (or stream ingestion) with payloads whose JS type alternates between `string` and `ArrayBuffer`/`Uint8Array` on the same connection instance within the buffered send window.
Common situations: Using a JSON hub protocol (text) but occasionally sending a raw byte payload, or switching hub protocols (JsonHubProtocol <-> MessagePackHubProtocol) on an already-established connection, or sending a Uint8Array where the buffer expected a string.
Related errors
- Binary protocols over XmlHttpRequest not implementing…
- Message is incomplete.
- Message is incomplete.
- Unknown value: .
- Unknown transport: .
AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11).
Data as JSON: /api/errors/46caf817c6f2757a.
Report an issue: GitHub.
Appendix: source
Thrown at src/SignalR/clients/ts/signalr/src/HttpConnection.ts:762
}
public send(data: string | ArrayBuffer): Promise<void> {
this._bufferData(data);
if (!this._transportResult) {
this._transportResult = new PromiseSource();
}
return this._transportResult.promise;
}
public stop(): Promise<void> {
this._executing = false;
this._sendBufferedData.resolve();
return this._sendLoopPromise;
}
private _bufferData(data: string | ArrayBuffer): void {
if (this._buffer.length && typeof(this._buffer[0]) !== typeof(data)) {
throw new Error(`Expected data to be of type ${typeof(this._buffer)} but was of type ${typeof(data)}`);
}
this._buffer.push(data);
this._sendBufferedData.resolve();
}
private async _sendLoop(): Promise<void> {
while (true) {
await this._sendBufferedData.promise;
if (!this._executing) {
if (this._transportResult) {
this._transportResult.reject("Connection stopped.");
}
break;
}
View on GitHub (pinned to 3600ca084e)