{"record":{"id":"133a44c865913d9c","repo":"Unity-Technologies/UnityCsReference","slug":"input-arrays-should-have-same-length","errorCode":null,"errorMessage":"Input arrays should have same length","messagePattern":"Input arrays should have same length","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GUI/TreeView/MultiColumnHeader.cs","lineNumber":78,"sourceCode":"            }\n        }\n\n        public MultiColumnHeader(MultiColumnHeaderState state)\n        {\n            m_State = state;\n            m_HeaderButtonsControlID = GUIUtility.GetPermanentControlID();\n        }\n\n        public void SetSortingColumns(int[] columnIndices, bool[] sortAscending)\n        {\n            if (columnIndices == null)\n                throw new ArgumentNullException(\"columnIndices\");\n\n            if (sortAscending == null)\n                throw new ArgumentNullException(\"sortAscending\");\n\n            if (columnIndices.Length != sortAscending.Length)\n                throw new ArgumentException(\"Input arrays should have same length\");\n\n            if (columnIndices.Length > state.maximumNumberOfSortedColumns)\n                throw new ArgumentException(\"The maximum number of sorted columns is \" + state.maximumNumberOfSortedColumns + \". Trying to set \" + columnIndices.Length + \" columns.\");\n\n            if (columnIndices.Length != columnIndices.DistinctCount())\n                throw new ArgumentException(\"Duplicate column indices are not allowed\", \"columnIndices\");\n\n            bool changed = false;\n\n            if (!columnIndices.AsSpan().SequenceEqual(state.sortedColumns))\n            {\n                state.sortedColumns = columnIndices;\n                changed = true;\n            }\n\n            for (int i = 0; i < columnIndices.Length; ++i)\n            {\n                var column = GetColumn(columnIndices[i]);","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GUI/TreeView/MultiColumnHeader.cs#L60-L96","documentation":"Thrown by SetSortingColumns when columnIndices and sortAscending have different lengths. The two arrays are zipped element-by-element, so a length mismatch means some columns would lack a sort direction or vice versa.","triggerScenarios":"Building the two arrays from different sources (e.g. columnIndices from saved state and sortAscending from a separate preference) that drifted out of sync.","commonSituations":"Partial deserialization where one array loaded fewer entries; UI state where the user changed selection count but the flags list wasn't updated.","solutions":["Derive both arrays from the same source list of (columnIndex, ascending) pairs.","Add an assertion columnIndices.Length == sortAscending.Length before calling.","Truncate or pad the shorter array intentionally, with a logged warning, if mismatch is expected."],"exampleFix":"// before\nheader.SetSortingColumns(cols, flags); // different lengths\n\n// after\nSystem.Diagnostics.Debug.Assert(cols.Length == flags.Length);\nheader.SetSortingColumns(cols, flags);","handlingStrategy":"validation","validationCode":"if (columnIndices.Length != sortAscending.Length) throw new InvalidOperationException(\"length mismatch\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Zip indices and flags from one source list to guarantee parity.","Assert equal lengths in debug builds before calling.","Avoid assembling the two arrays from independent data paths."],"tags":["unity-editor","treeview","multicolumn","validation"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}