{"record":{"id":"e4b1862a941dc844","repo":"clockworklabs/SpacetimeDB","slug":"expected-identity-hex-string-to-be-64-characters-l","errorCode":null,"errorMessage":"Expected Identity hex string to be 64 characters long, but was {hex.Length}.","messagePattern":"Expected Identity hex string to be 64 characters long, but was (.+?)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"crates/bindings-csharp/BSATN.Runtime/Builtins.cs","lineNumber":290,"sourceCode":"    ///\n    /// \"0xb0b1b2...\"\n    /// ->\n    /// [0xb0, 0xb1, 0xb2, ...]\n    /// </summary>\n    /// <param name=\"bytes\"></param>\n    public static Identity FromBigEndian(ReadOnlySpan<byte> bytes) =>\n        Util.Read<Identity>(bytes, littleEndian: false);\n\n    /// <summary>\n    /// Create an Identity from a hex string.\n    /// </summary>\n    /// <param name=\"hex\"></param>\n    /// <returns></returns>\n    public static Identity FromHexString(string hex)\n    {\n        if (hex.Length != 64)\n        {\n            throw new ArgumentException(\n                $\"Expected Identity hex string to be 64 characters long, but was {hex.Length}.\",\n                nameof(hex)\n            );\n        }\n\n        return FromBigEndian(Util.StringToByteArray(hex));\n    }\n\n    // --- auto-generated ---\n    public readonly struct BSATN : IReadWrite<Identity>\n    {\n        public Identity Read(BinaryReader reader) => new(new SpacetimeDB.BSATN.U256().Read(reader));\n\n        public void Write(BinaryWriter writer, Identity value) =>\n            new SpacetimeDB.BSATN.U256().Write(writer, value.value);\n\n        // --- / auto-generated ---\n","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings-csharp/BSATN.Runtime/Builtins.cs#L272-L308","documentation":"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.","triggerScenarios":"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.","commonSituations":"Mixing up the two identifier hex formats when wiring authentication or logging identities; prefixes from external tooling; partial copy-paste of long ids.","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"],"exampleFix":"// before\nvar id = Identity.FromHexString(connectionHex32Chars); // ArgumentException: Expected ... 64 characters long\n\n// after\nvar cid = ConnectionId.FromHexString(connectionHex32Chars);","handlingStrategy":"validation","validationCode":"using System.Text.RegularExpressions;\n\nstatic bool IsIdentityHex(string s) => Regex.IsMatch(s, \"^[0-9a-fA-F]{64}$\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate the 64-char shape before parsing","Route 32-char strings to ConnectionId.FromHexString","Normalize prefixes/whitespace from logs and JSON before parsing"],"tags":["csharp","spacetimedb","identity","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"}