{"record":{"id":"27d241022ce49791","repo":"clockworklabs/SpacetimeDB","slug":"expected-connectionid-hex-string-to-be-32-characte","errorCode":null,"errorMessage":"Expected ConnectionId hex string to be 32 characters long, but was {hex.Length}.","messagePattern":"Expected ConnectionId hex string to be 32 characters long, but was (.+?)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"crates/bindings-csharp/BSATN.Runtime/Builtins.cs","lineNumber":178,"sourceCode":"    /// Returns null if the resulting ConnectionId is the default.\n    /// </summary>\n    /// <param name=\"bytes\"></param>\n    public static ConnectionId? FromBigEndian(ReadOnlySpan<byte> bytes)\n    {\n        var id = Util.Read<ConnectionId>(bytes, littleEndian: false);\n        return id == default ? null : id;\n    }\n\n    /// <summary>\n    /// Create a ConnectionId from a hex string.\n    /// </summary>\n    /// <param name=\"hex\"></param>\n    /// <returns></returns>\n    public static ConnectionId? FromHexString(string hex)\n    {\n        if (hex.Length != 32)\n        {\n            throw new ArgumentException(\n                $\"Expected ConnectionId hex string to be 32 characters long, but was {hex.Length}.\",\n                nameof(hex)\n            );\n        }\n\n        return FromBigEndian(Util.StringToByteArray(hex));\n    }\n\n    public static ConnectionId Random()\n    {\n        var random = new Random();\n        var id = new ConnectionId();\n        random.NextBytes(Util.AsBytes(ref id));\n        return id;\n    }\n\n    // --- auto-generated ---\n    public readonly struct BSATN : IReadWrite<ConnectionId>","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/bindings-csharp/BSATN.Runtime/Builtins.cs#L160-L196","documentation":"ConnectionId.FromHexString requires exactly 32 hex characters because a ConnectionId is a 16-byte value and the hex parser does not strip prefixes, separators, or padding. Any other length is rejected with ArgumentException before any parsing happens.","triggerScenarios":"Passing a string with a \"0x\" prefix (34 chars); a dash-formatted UUID-like string (36 chars); an Identity hex string (64 chars); an empty string; a hex string that was truncated or had whitespace appended.","commonSituations":"Copy-pasting IDs of the wrong kind (Identity vs ConnectionId vs Address) from logs or dashboards; concatenating/parsing IDs with formatting helpers that add prefixes or newlines.","solutions":["Pass exactly 32 hex characters (16 bytes) with no 0x prefix, dashes, braces, or whitespace","Double-check you have the right ID type: ConnectionId = 32 chars, Identity = 64 chars","Normalize input before calling: strip 0x/dashes/whitespace, then verify length == 32","Source IDs from ConnectionId.ToHexString()/ ToString outputs, which are already canonical"],"exampleFix":"// before\nvar id = ConnectionId.FromHexString(raw.Trim()); // \"0x6a1c...\" -> 34 chars, throws\n\n// after\nvar hex = raw.Trim().Replace(\"-\", \"\");\nif (hex.StartsWith(\"0x\", StringComparison.OrdinalIgnoreCase)) hex = hex[2..];\nvar id = ConnectionId.FromHexString(hex);","handlingStrategy":"validation","validationCode":"static bool IsValidConnectionIdHex(string hex) =>\n    hex.Length == 32 && hex.All(c => c is (>= '0' and <= '9') or (>= 'a' and <= 'f') or (>= 'A' and <= 'F'));\n\nif (IsValidConnectionIdHex(hex)) { var id = ConnectionId.FromHexString(hex); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Route all external ID strings through a normalizer that strips 0x, dashes, and whitespace","Document the per-type lengths (ConnectionId 32, Identity 64) at input boundaries","Round-trip IDs via ToHexString so stored values are always canonical"],"tags":["csharp","connection-id","hex-string","argument-validation","spacetimedb"],"backgroundTag":"hex-string-length-mismatch","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}