{"record":{"id":"833034119753d62c","repo":"dotnet/orleans","slug":"azure-table-partition-keys-must-not-exceed-1-024-c","errorCode":null,"errorMessage":"Azure Table partition keys must not exceed 1,024 characters.","messagePattern":"Azure Table partition keys must not exceed 1,024 characters\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Azure/Orleans.Journaling.AzureStorage/AzureTableJournalStorageOptions.cs","lineNumber":154,"sourceCode":"                nameof(TableName));\n        }\n\n        foreach (var character in tableName)\n        {\n            if (!IsAsciiLetter(character) && character is not (>= '0' and <= '9'))\n            {\n                throw new ArgumentException(\n                    \"Azure Table names must contain 3 to 63 alphanumeric characters and begin with a letter.\",\n                    nameof(TableName));\n            }\n        }\n    }\n\n    private static void ValidatePartitionKey(string partitionKey, string parameterName)\n    {\n        if (partitionKey.Length > 1024)\n        {\n            throw new ArgumentException(\n                \"Azure Table partition keys must not exceed 1,024 characters.\",\n                parameterName);\n        }\n\n        foreach (var character in partitionKey)\n        {\n            if (character is '/' or '\\\\' or '#' or '?'\n                or >= '\\u0000' and <= '\\u001F'\n                or >= '\\u007F' and <= '\\u009F')\n            {\n                throw new ArgumentException(\n                    \"Azure Table partition keys must not contain '/', '\\\\', '#', '?', or control characters.\",\n                    parameterName);\n            }\n        }\n    }\n\n    private static bool IsAsciiLetter(char character)","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/dotnet/orleans/blob/fca799fa70ecb6ad975224271703ca43221f58de/src/Azure/Orleans.Journaling.AzureStorage/AzureTableJournalStorageOptions.cs#L136-L172","documentation":"Thrown by ValidatePartitionKey when a computed partition key exceeds 1,024 characters. Azure Tables caps partition keys at 1 KiB; this check prevents a request that the service would reject, and applies to both the default percent-encoding mapper and custom mappers.","triggerScenarios":"A JournalId.Value is long enough that Uri.EscapeDataString (or a custom GetPartitionKey mapper) produces a string longer than 1,024 chars; ValidatePartitionKey is then called from GetPartitionKeyForJournal or GetDefaultPartitionKey.","commonSituations":"Using a very long grain-type name or a composite key as the JournalId value; a custom mapper that concatenates multiple fields without truncation; percent-encoding triples the length of certain characters, inflating an already-long id.","solutions":["Shorten the JournalId.Value source so the encoded key stays under 1,024 chars.","Provide a custom GetPartitionKey mapper that hashes or truncates the id deterministically (e.g. a stable hash) while remaining unique enough.","Avoid embedding full type names/URIs into the JournalId value."],"exampleFix":"// before\nvar journalId = new JournalId(grainType.FullName + \":\" + key); // may encode >1024\n// after\nvar journalId = new JournalId(Sha1Hash(grainType.FullName + \":\" + key));","handlingStrategy":"validation","validationCode":"var encoded = Uri.EscapeDataString(journalId.Value);\nif (encoded.Length > 1024)\n    throw new ArgumentException(\"Encoded partition key exceeds 1024 chars; shorten or hash the id.\");","typeGuard":"static bool FitsPartitionKeyLimit(JournalId id) => Uri.EscapeDataString(id.Value).Length <= 1024;","tryCatchPattern":null,"preventionTips":["Keep JournalId.Value sources short; avoid full type names or URLs.","If ids can be long, use a custom mapper with a stable hash.","Remember percent-encoding can triple the length of special chars."],"tags":["azure-table-storage","journaling","validation","partition-key","size-limit"],"backgroundTag":null,"analyzedSha":"fca799fa70ecb6ad975224271703ca43221f58de","analyzedAt":"2026-08-13T19:55:57.938Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}