clockworklabs/SpacetimeDB · error · ArgumentException
Expected ConnectionId hex string to be 32 characters long…
Error message
Expected ConnectionId hex string to be 32 characters long, but was {hex.Length}. What it means
ConnectionId.FromHexString parses a 32-character hex string (16 bytes, 128-bit id). The length is validated before any decoding, so any other character count throws ArgumentException immediately.
Solutions
- Supply exactly 32 hex characters for a ConnectionId
- If the string is 64 chars you are holding an Identity — use Identity.FromHexString instead
- Strip 0x prefixes and whitespace, and validate length before calling
Example fix
// before var cid = ConnectionId.FromHexString(identityHex64Chars); // ArgumentException: Expected ... 32 characters long // after var identity = Identity.FromHexString(identityHex64Chars);
Defensive patterns
Strategy: validation
Validate before calling
using System.Text.RegularExpressions;
static bool IsConnectionIdHex(string s) => Regex.IsMatch(s, "^[0-9a-fA-F]{32}$"); Prevention
- Validate the 32-char shape before parsing
- Normalize input: trim whitespace and strip 0x prefixes
- Route 64-char strings to Identity.FromHexString
When it happens
Trigger: Passing a 64-character Identity hex string where a ConnectionId was expected; an id copied with a 0x prefix (34 chars); a truncated copy-paste; an empty string.
Common situations: Confusing the two identifier types when reading logs or dashboards; hex prefixed by other tooling; whitespace or formatting introduced by JSON round-trips.
Related errors
- Argument must be a ConnectionId
- Expected Identity hex string to be 64 characters long, but…
- Argument must be a I128
- Argument must be a I256
- Argument must be a Identity
AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20).
Data as JSON: /api/errors/27d241022ce49791.
Report an issue: GitHub.
Appendix: source
Thrown at crates/bindings-csharp/BSATN.Runtime/Builtins.cs:178
/// Returns null if the resulting ConnectionId is the default.
/// </summary>
/// <param name="bytes"></param>
public static ConnectionId? FromBigEndian(ReadOnlySpan<byte> bytes)
{
var id = Util.Read<ConnectionId>(bytes, littleEndian: false);
return id == default ? null : id;
}
/// <summary>
/// Create a ConnectionId from a hex string.
/// </summary>
/// <param name="hex"></param>
/// <returns></returns>
public static ConnectionId? FromHexString(string hex)
{
if (hex.Length != 32)
{
throw new ArgumentException(
$"Expected ConnectionId hex string to be 32 characters long, but was {hex.Length}.",
nameof(hex)
);
}
return FromBigEndian(Util.StringToByteArray(hex));
}
public static ConnectionId Random()
{
var random = new Random();
var id = new ConnectionId();
random.NextBytes(Util.AsBytes(ref id));
return id;
}
// --- auto-generated ---
public readonly struct BSATN : IReadWrite<ConnectionId>View on GitHub (pinned to 6dee26c6ef)