{"record":{"id":"81048039d2ed61be","repo":"dotnet/orleans","slug":"key-length-0-is-too-long-to-be-an-dynamodb-row-k","errorCode":null,"errorMessage":"Key length {0} is too long to be an DynamoDB row key. Key={1}","messagePattern":"Key length (.+?) is too long to be an DynamoDB row key\\. Key=(.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/AWS/Shared/AWSUtils.cs","lineNumber":58,"sourceCode":"        /// <param name=\"key\"></param>\n        /// <returns></returns>\n        public static string ValidateDynamoDBPartitionKey(string key)\n        {\n            if (key.Length >= 2048)\n                throw new ArgumentException(string.Format(\"Key length {0} is too long to be an DynamoDB partition key. Key={1}\", key.Length, key));\n\n            return key;\n        }\n\n        /// <summary>\n        /// Validate DynamoDB RowKey.\n        /// </summary>\n        /// <param name=\"key\"></param>\n        /// <returns></returns>\n        public static string ValidateDynamoDBRowKey(string key)\n        {\n            if (key.Length >= 1024)\n                throw new ArgumentException(string.Format(\"Key length {0} is too long to be an DynamoDB row key. Key={1}\", key.Length, key));\n\n            return key;\n        }\n    }\n}\n","sourceCodeStart":40,"sourceCodeEnd":64,"githubUrl":"https://github.com/dotnet/orleans/blob/fca799fa70ecb6ad975224271703ca43221f58de/src/AWS/Shared/AWSUtils.cs#L40-L64","documentation":"Thrown by AWSUtils.ValidateDynamoDBRowKey when the supplied row (sort) key string is 1024 characters or longer. DynamoDB limits a sort key attribute to 1024 bytes (UTF-8); this guard rejects oversized sort keys up front with a message reporting the length and the key value.","triggerScenarios":"Produced wherever a DynamoDB row/sort key is built and validated (transactional state row keys, persistence row keys). Triggered when the composed row key — often a sequence-id-prefixed or transaction-id-prefixed string — exceeds 1024 chars, or when a custom row-key scheme packs too much into the sort key.","commonSituations":"Custom row-key formatting that embeds transaction ids, timestamps, or long identifiers; a fork that changed the row-key layout to include extra fields; very long state names or sequence prefixes concatenated into the row key.","solutions":["Shorten the components that make up the row key and keep only what is needed for ordering/identity.","If a long value must be encoded, hash it to a fixed width and store the original in a separate attribute.","Review the row-key construction in your provider usage and remove redundant segments.","Keep the composed key well under 1024 bytes to allow for multi-byte UTF-8 characters."],"exampleFix":"// before: row key embeds a long transaction id + timestamp + label\nstring rowKey = $\"{txId}_{timestamp}_{longLabel}\"; // may exceed 1024\n\n// after: keep row key compact, store extras as attributes\nstring rowKey = $\"{timestamp:D20}_{txIdHash}\";","handlingStrategy":"validation","validationCode":"string SafeRowKey(string raw)\n{\n    if (string.IsNullOrEmpty(raw) || raw.Length >= 1024)\n        return Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(raw ?? Guid.NewGuid().ToString())));\n    return raw;\n}","typeGuard":"static bool IsValidRowKey(string key) => !string.IsNullOrEmpty(key) && key.Length < 1024;","tryCatchPattern":"try { AWSUtils.ValidateDynamoDBRowKey(key); }\ncatch (ArgumentException ax) when (ax.Message.Contains(\"row key\"))\n{\n    key = Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(key)));\n}","preventionTips":["Keep row/sort keys compact; store extras in attributes, not in the key.","Avoid embedding long transaction ids/timestamps/labels directly into row keys.","Hash long components to a fixed width before composing the row key.","Leave headroom under 1024 bytes for multi-byte UTF-8."],"tags":["dynamodb","row-key","sort-key","validation","key-size"],"backgroundTag":null,"analyzedSha":"fca799fa70ecb6ad975224271703ca43221f58de","analyzedAt":"2026-08-13T19:55:57.938Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}