{"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/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings-csharp/BSATN.Runtime/Builtins.cs#L160-L196","documentation":"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.","triggerScenarios":"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.","commonSituations":"Confusing the two identifier types when reading logs or dashboards; hex prefixed by other tooling; whitespace or formatting introduced by JSON round-trips.","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"],"exampleFix":"// before\nvar cid = ConnectionId.FromHexString(identityHex64Chars); // ArgumentException: Expected ... 32 characters long\n\n// after\nvar identity = Identity.FromHexString(identityHex64Chars);","handlingStrategy":"validation","validationCode":"using System.Text.RegularExpressions;\n\nstatic bool IsConnectionIdHex(string s) => Regex.IsMatch(s, \"^[0-9a-fA-F]{32}$\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate the 32-char shape before parsing","Normalize input: trim whitespace and strip 0x prefixes","Route 64-char strings to Identity.FromHexString"],"tags":["csharp","spacetimedb","connectionid","hex"],"backgroundTag":"hex-string-length-mismatch","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}