Unity-Technologies/UnityCsReference · error · Exception
Received corrupted message
Error message
Received corrupted message
What it means
Thrown by the ReadString helper inside PlayerConnectionLogReceiver.LogMessageMultiple when deserializing a log message payload from a connected player and the byte-length prefix of a string field is negative. A negative length indicates the payload is malformed or corrupted — either truncated, byte-misaligned, or from an incompatible player/editor protocol version. The method reads log type, message, timestamp, and stacktrace strings sequentially from the payload buffer.
Source
Thrown at Editor/Mono/PlayerConnectionLogReceiver.cs:137
var name = ConnectionUIHelper.GetPlayerNameFromId(messageEventArgs.playerId);
var t = ConnectionUIHelper.GetPlayerType(ProfilerDriver.GetConnectionIdentifier(messageEventArgs.playerId));
var messagePrefix = $"<i>{t} \"{name}\"</i> ";
var prefixUtf8Bytes = Encoding.UTF8.GetBytes(messagePrefix);
fixed (byte* payloadPtr = messageEventArgs.data.AsSpan<byte>())
fixed (byte* prefixUtf8Ptr = prefixUtf8Bytes)
{
static UTF8StringView ReadString(byte* payload, ref int offset)
{
var bytesLength = BitConverter.ToInt32(new ReadOnlySpan<byte>(payload + offset, 4));
offset += 4;
if (bytesLength == 0)
return default;
if (bytesLength < 0)
throw new Exception("Received corrupted message");
var utf8StringPtr = payload + offset;
offset += bytesLength;
return new UTF8StringView(utf8StringPtr, bytesLength);
}
static LogMessageFlags FlagsFromType(LogType type)
{
switch (type)
{
case LogType.Warning: return LogMessageFlags.DebugWarning;
case LogType.Error: return LogMessageFlags.DebugError;
case LogType.Assert: return LogMessageFlags.DebugAssert;
case LogType.Exception: return LogMessageFlags.DebugException;
}
return LogMessageFlags.DebugLog;
}
View on GitHub (pinned to 225b0fbdb5)
Solutions
- Ensure the connected player is built with the same Unity version as the editor to avoid protocol mismatches.
- Check the player connection network stability — unstable connections can produce truncated payloads.
- If developing a custom connection, verify your binary payload matches the expected format (4-byte Int32 length prefix per string field, in order: logType, message, timestamp, stacktrace).
Defensive patterns
Strategy: validation
Prevention
- Build players with the same Unity version as the editor to avoid protocol mismatches.
- Ensure network stability for player connections — unstable links produce truncated payloads.
- Validate custom player connection payloads match the expected binary format before sending.
When it happens
Trigger: A connected player (via Player Connection / Profiler connection) sends a log message batch whose binary payload is corrupted or uses an incompatible serialization format. The ReadString function reads a 4-byte Int32 length prefix; if that value is negative, the payload is unrecoverable.
Common situations: Connecting a player built with a different Unity version than the editor; network corruption or packet loss on the player connection; player crash mid-transmission producing a truncated payload; debugging a custom player connection protocol that sends malformed data.
Related errors
- Unexpected resultBits Span length. The expected length of re
- ScriptableBakedReflectionSystemWrapper
- Not a valid handle, has it been released already?
- GetInstallationForPath: Does not allow null editorPath
- GetCodeEditorForPath: Does not allow null editorPath
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/f55ae3e760573d52.
Report an issue: GitHub.