{"record":{"id":"5ed5102f7a9b133d","repo":"dotnet/machinelearning","slug":"null","errorCode":null,"errorMessage":"null","messagePattern":"null","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/DataFrameColumnCollection.cs","lineNumber":105,"sourceCode":"                throw new ArgumentException(string.Format(Strings.DuplicateColumnName, column.Name), nameof(column));\n            }\n\n            column.AddOwner(this);\n\n            RowCount = column.Length;\n\n            _columnNameToIndexDictionary[column.Name] = columnIndex;\n            for (int i = columnIndex; i < Count; i++)\n            {\n                _columnNameToIndexDictionary[this[i].Name]++;\n            }\n            base.InsertItem(columnIndex, column);\n            ColumnsChanged?.Invoke();\n        }\n\n        protected override void SetItem(int columnIndex, DataFrameColumn column)\n        {\n            column = column ?? throw new ArgumentNullException(nameof(column));\n            if (RowCount > 0 && column.Length != RowCount)\n            {\n                throw new ArgumentException(Strings.MismatchedColumnLengths, nameof(column));\n            }\n            bool existingColumn = _columnNameToIndexDictionary.TryGetValue(column.Name, out int existingColumnIndex);\n            if (existingColumn && existingColumnIndex != columnIndex)\n            {\n                throw new ArgumentException(string.Format(Strings.DuplicateColumnName, column.Name), nameof(column));\n            }\n\n            _columnNameToIndexDictionary.Remove(this[columnIndex].Name);\n            _columnNameToIndexDictionary[column.Name] = columnIndex;\n\n            this[columnIndex].RemoveOwner(this);\n            base.SetItem(columnIndex, column);\n\n            ColumnsChanged?.Invoke();\n        }","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/DataFrameColumnCollection.cs#L87-L123","documentation":"SetItem (triggered by assigning collection[index] = column or ReplaceColumn) throws ArgumentNullException when the replacement DataFrameColumn is null. The null-coalescing throw pattern uses the parameter name 'column'.","triggerScenarios":"Executing columns[0] = null; or any API that replaces a column slot with a null reference.","commonSituations":"Null-propagation from a failed factory method or deserialization producing null columns, then assigning into the collection; optional column variables that turn out to be null.","solutions":["Pass a non-null DataFrameColumn; construct the column before assignment.","Check for null before assigning and skip or throw a domain-specific error.","If the intent is removal, use Remove/RemoveAt instead of assigning null."],"exampleFix":"// before\ndf.Columns[0] = maybeNullColumn;\n// after\nif (maybeNullColumn != null)\n    df.Columns[0] = maybeNullColumn;","handlingStrategy":"validation","validationCode":"if (replacement == null)\n    throw new InvalidOperationException(\"Replacement column must not be null\");\ndf.Columns[index] = replacement;","typeGuard":"bool IsValidReplacement(DataFrameColumn c) => c != null;","tryCatchPattern":"try\n{\n    df.Columns[index] = column;\n}\ncatch (ArgumentNullException ex)\n{\n    // column was null; construct or skip\n}","preventionTips":["Never assign collection slots from nullable column variables without a null check.","Use RemoveAt instead of assigning null to 'delete' a column.","Ensure column factory methods cannot return null (use throw on failure)."],"tags":["dataframe","null-argument","dotnet"],"backgroundTag":"null-argument","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}