clockworklabs/SpacetimeDB · error · ArgumentException
Expected Identity hex string to be 64 characters long, but…
Error message
Expected Identity hex string to be 64 characters long, but was {hex.Length}. What it means
Identity.FromHexString parses a 64-character hex string (32 bytes, 256-bit id). The character count is validated up front; any other length throws ArgumentException before decoding begins.
Solutions
- Supply exactly 64 hex characters for an Identity
- If the string is 32 chars it is a ConnectionId — use ConnectionId.FromHexString
- Normalize input (strip 0x and whitespace) and validate length before calling
Example fix
// before var id = Identity.FromHexString(connectionHex32Chars); // ArgumentException: Expected ... 64 characters long // after var cid = ConnectionId.FromHexString(connectionHex32Chars);
Defensive patterns
Strategy: validation
Validate before calling
using System.Text.RegularExpressions;
static bool IsIdentityHex(string s) => Regex.IsMatch(s, "^[0-9a-fA-F]{64}$"); Prevention
- Validate the 64-char shape before parsing
- Route 32-char strings to ConnectionId.FromHexString
- Normalize prefixes/whitespace from logs and JSON before parsing
When it happens
Trigger: Passing a 32-character ConnectionId hex string where an Identity was expected; an identity copied with a 0x prefix (66 chars); truncated or whitespace-padded input from JSON or logs.
Common situations: Mixing up the two identifier hex formats when wiring authentication or logging identities; prefixes from external tooling; partial copy-paste of long ids.
Related errors
- Argument must be a Identity
- Expected ConnectionId hex string to be 32 characters long…
- Argument must be a ConnectionId
- Argument must be a I128
- Argument must be a I256
AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20).
Data as JSON: /api/errors/e4b1862a941dc844.
Report an issue: GitHub.
Appendix: source
Thrown at crates/bindings-csharp/BSATN.Runtime/Builtins.cs:290
///
/// "0xb0b1b2..."
/// ->
/// [0xb0, 0xb1, 0xb2, ...]
/// </summary>
/// <param name="bytes"></param>
public static Identity FromBigEndian(ReadOnlySpan<byte> bytes) =>
Util.Read<Identity>(bytes, littleEndian: false);
/// <summary>
/// Create an Identity from a hex string.
/// </summary>
/// <param name="hex"></param>
/// <returns></returns>
public static Identity FromHexString(string hex)
{
if (hex.Length != 64)
{
throw new ArgumentException(
$"Expected Identity hex string to be 64 characters long, but was {hex.Length}.",
nameof(hex)
);
}
return FromBigEndian(Util.StringToByteArray(hex));
}
// --- auto-generated ---
public readonly struct BSATN : IReadWrite<Identity>
{
public Identity Read(BinaryReader reader) => new(new SpacetimeDB.BSATN.U256().Read(reader));
public void Write(BinaryWriter writer, Identity value) =>
new SpacetimeDB.BSATN.U256().Write(writer, value.value);
// --- / auto-generated ---
View on GitHub (pinned to 6dee26c6ef)