{"record":{"id":"920174389021ec0e","repo":"OrchardCMS/OrchardCore","slug":"parameters-must-have-the-same-length","errorCode":null,"errorMessage":"Parameters must have the same length","messagePattern":"Parameters must have the same length","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Utilities/StringExtensions.cs","lineNumber":300,"sourceCode":"        }\n\n        return true;\n    }\n\n    public static string Translate(this string subject, char[] from, char[] to)\n    {\n        if (string.IsNullOrEmpty(subject))\n        {\n            return subject;\n        }\n\n        ArgumentNullException.ThrowIfNull(from);\n\n        ArgumentNullException.ThrowIfNull(to);\n\n        if (from.Length != to.Length)\n        {\n            throw new ArgumentNullException(nameof(from), \"Parameters must have the same length\");\n        }\n\n        var map = new Dictionary<char, char>(from.Length);\n        for (var i = 0; i < from.Length; i++)\n        {\n            map[from[i]] = to[i];\n        }\n\n        var result = new char[subject.Length];\n\n        for (var i = 0; i < subject.Length; i++)\n        {\n            var current = subject[i];\n            if (map.TryGetValue(current, out var value))\n            {\n                result[i] = value;\n            }\n            else","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Utilities/StringExtensions.cs#L282-L318","documentation":"StringExtensions.Translate(from, to) builds a character mapping table and requires the 'from' and 'to' character arrays to be the same length so each source char has exactly one replacement. When lengths differ there is no valid pairing, so it throws ArgumentNullException with this message (using nameof(from) as the param name).","triggerScenarios":"Calling aString.Translate(fromChars, toChars) where from.Length != to.Length, e.g. Translate(new[]{'a','b'}, new[]{'x'})","commonSituations":"Hand-written transliteration tables where one source character was added but its replacement was forgotten; building the arrays dynamically from a config string split that produced uneven sides","solutions":["Make both arrays the same length, padding 'to' with a replacement (e.g. space or the original char) for extra 'from' entries","Add a guard that trims 'from' to 'to'.Length or throws early with a clear message","Move the transliteration table to a single data structure (e.g. pairs) that cannot desynchronize"],"exampleFix":"// before\nvar result = name.Translate(new[] { 'ä', 'ö', 'ü', 'ß' }, new[] { 'a', 'o', 'u' });\n// after\nvar result = name.Translate(new[] { 'ä', 'ö', 'ü', 'ß' }, new[] { 'a', 'o', 'u', 's' });","handlingStrategy":"validation","validationCode":"if (from.Length != to.Length)\n    throw new ArgumentException(\"Translate maps must have equal-length 'from' and 'to' arrays.\");\nvar result = value.Translate(from, to);","typeGuard":null,"tryCatchPattern":"try\n{\n    result = value.Translate(fromChars, toChars);\n}\ncatch (ArgumentNullException ex) when (ex.Message.Contains(\"same length\"))\n{\n    _logger.LogError(ex, \"Transliteration table lengths differ: {From} vs {To}\", fromChars.Length, toChars.Length);\n}","preventionTips":["Define transliteration tables as paired tuples so entries cannot desynchronize","Add a startup or unit-test check that all from/to tables have equal length","Whenever adding a source character, add its replacement in the same commit"],"tags":["string-extensions","argument-validation","transliteration"],"backgroundTag":"invalid-argument-value","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}