{"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/524b4487d949b61a07d4f39c862d1290259dfd20/crates/bindings-csharp/BSATN.Runtime/Builtins.cs#L272-L308","documentation":"Identity.FromHexString requires exactly 64 hex characters because an Identity wraps a 256-bit (32-byte) value. The length check runs before parsing, so any string of a different length fails immediately with ArgumentException instead of producing a malformed identity.","triggerScenarios":"Passing a ConnectionId hex string (32 chars) or an Ethereum-style address (40 chars); a string with 0x prefix (66 chars); dash/brace-formatted strings; truncated or whitespace-padded input.","commonSituations":"Confusing which ID a UI/config field expects (Identity vs ConnectionId vs Address); pasting values from wallet-style tooling that includes 0x; string manipulation that trims or adds characters.","solutions":["Pass exactly 64 hex characters (32 bytes) with no prefix or separators","Verify the ID kind first - Identity is 64 chars, ConnectionId is 32 chars - and pick the matching FromHexString","Normalize (strip 0x/dashes/whitespace) before calling and assert length == 64","Generate canonical strings via Identity.ToHexString() for storage and round-tripping"],"exampleFix":"// before\nvar identity = Identity.FromHexString(userInput); // \"0x\" + 64 chars -> 66, throws\n\n// after\nvar hex = userInput.Trim();\nif (hex.StartsWith(\"0x\", StringComparison.OrdinalIgnoreCase)) hex = hex[2..];\nvar identity = Identity.FromHexString(hex);","handlingStrategy":"validation","validationCode":"static bool IsValidIdentityHex(string hex) =>\n    hex.Length == 64 && hex.All(c => c is (>= '0' and <= '9') or (>= 'a' and <= 'f') or (>= 'A' and <= 'F'));\n\nif (IsValidIdentityHex(hex)) { var id = Identity.FromHexString(hex); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Strip 0x prefixes and separators before calling FromHexString","Distinguish ID kinds at the UI/API boundary (Identity = 64 chars, ConnectionId = 32)","Persist canonical ToHexString() output only"],"tags":["csharp","identity","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"}