{"record":{"id":"f4bf52c5e7f8ef4c","repo":"Unity-Technologies/UnityCsReference","slug":"visiblecolumns-should-not-be-set-to-null","errorCode":null,"errorMessage":"visibleColumns should not be set to null","messagePattern":"visibleColumns should not be set to null","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GUI/TreeView/MultiColumnHeaderState.cs","lineNumber":182,"sourceCode":"            set\n            {\n                m_SortedColumns = value == null ? new List<int>() : new List<int>(value);\n                RemoveInvalidSortingColumnsIndices();\n            }\n        }\n\n        public Column[] columns\n        {\n            get { return m_Columns; }\n        }\n\n        public int[] visibleColumns\n        {\n            get { return m_VisibleColumns; }\n            set\n            {\n                if (value == null)\n                    throw new ArgumentException(\"visibleColumns should not be set to null\");\n                if (value.Length == 0)\n                    throw new ArgumentException(\"visibleColumns should should not be set to an empty array. At least one visible column is required.\");\n                m_VisibleColumns = value;\n            }\n        }\n\n        public float widthOfAllVisibleColumns\n        {\n#pragma warning disable UA2001 // The Banned API Analyzer produces compile errors for any new Linq code. This pre-existing usage has been suppressed, but should be rewritten if possible.\n            get { return visibleColumns.Sum(t => columns[t].width); }\n#pragma warning restore UA2001\n        }\n    }\n}\n","sourceCodeStart":164,"sourceCodeEnd":197,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GUI/TreeView/MultiColumnHeaderState.cs#L164-L197","documentation":"Thrown by the MultiColumnHeaderState.visibleColumns setter when null is assigned. At least one visible column is required for the header to render any content, so null is explicitly rejected.","triggerScenarios":"Assigning header.state.visibleColumns = null; binding to a visibility preference that deserialized to null.","commonSituations":"Resetting visibility to 'show all' but mistakenly assigning null; a corrupted preferences file yielding null for the visible-columns array.","solutions":["To show all columns, assign an array of all indices {0..columns.Length-1} rather than null.","Null-coalesce loaded preferences: visibleColumns = loaded ?? allIndices.","Guard the setter call with a null check and default to the full index set."],"exampleFix":"// before\nstate.visibleColumns = loadedVisible; // may be null\n\n// after\nint[] all = Enumerable.Range(0, state.columns.Length).ToArray();\nstate.visibleColumns = loadedVisible ?? all;","handlingStrategy":"validation","validationCode":"state.visibleColumns = value ?? Enumerable.Range(0, state.columns.Length).ToArray();","typeGuard":"static bool HasVisibleColumns(MultiColumnHeaderState s) => s.visibleColumns != null && s.visibleColumns.Length > 0;","tryCatchPattern":null,"preventionTips":["Assign the full index set instead of null to 'show all'.","Null-coalesce deserialized visibility preferences.","Default visibility arrays to all indices at construction."],"tags":["unity-editor","treeview","multicolumn","null-check"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}