{"record":{"id":"d5f50e797a6826ab","repo":"dotnet/machinelearning","slug":"strings-invalidcolumnname-formatted-with-columnna","errorCode":null,"errorMessage":"Strings.InvalidColumnName (formatted with columnName)","messagePattern":"Strings\\.InvalidColumnName \\(formatted with columnName\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/DataFrameColumnCollection.cs","lineNumber":188,"sourceCode":"\n            //reset RowCount as DataFrame is now empty\n            RowCount = 0;\n        }\n\n        /// <summary>\n        /// An indexer based on <see cref=\"DataFrameColumn.Name\"/>\n        /// </summary>\n        /// <param name=\"columnName\">The name of a <see cref=\"DataFrameColumn\"/></param>\n        /// <returns>A <see cref=\"DataFrameColumn\"/> if it exists.</returns>\n        /// <exception cref=\"ArgumentException\">Throws if <paramref name=\"columnName\"/> is not present in this <see cref=\"DataFrame\"/></exception>\n        public DataFrameColumn this[string columnName]\n        {\n            get\n            {\n                int columnIndex = IndexOf(columnName);\n                if (columnIndex == -1)\n                {\n                    throw new ArgumentException(String.Format(Strings.InvalidColumnName, columnName), nameof(columnName));\n                }\n                return this[columnIndex];\n            }\n            set\n            {\n                int columnIndex = IndexOf(columnName);\n                DataFrameColumn newColumn = value;\n                newColumn.SetName(columnName);\n                if (columnIndex == -1)\n                {\n                    Insert(Count, newColumn);\n                }\n                else\n                {\n                    this[columnIndex] = newColumn;\n                }\n            }\n        }","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/DataFrameColumnCollection.cs#L170-L206","documentation":"The DataFrameColumnCollection indexer by name throws ArgumentException(Strings.InvalidColumnName, columnName) when no column with that name exists (IndexOf returns -1). It is the getter for collection[columnName].","triggerScenarios":"Reading df.Columns[\"colName\"] (or the setter) with a name not present in the collection.","commonSituations":"Typos or casing mismatches in column names, schema changes between file versions (renamed CSV/parquet headers), column dropped in an earlier pipeline step.","solutions":["Verify the exact name with df.Columns.Contains(name) before indexing.","List available names (foreach over df.Columns) to spot typos.","Use TryGetColumnIndex or IndexOf and handle the miss gracefully."],"exampleFix":"// before\nvar col = df.Columns[\"Sals\"]; // typo\n// after\nif (df.Columns.Contains(\"Sales\"))\n    var col = df.Columns[\"Sales\"];","handlingStrategy":"validation","validationCode":"if (!df.Columns.Contains(\"Sales\"))\n    throw new InvalidOperationException(\"Missing expected column 'Sales'\");\nvar col = df.Columns[\"Sales\"];","typeGuard":"bool TryGetColumn(DataFrame df, string name, out DataFrameColumn col)\n{\n    var i = df.Columns.IndexOf(name);\n    col = i >= 0 ? df.Columns[i] : null;\n    return i >= 0;\n}","tryCatchPattern":"try\n{\n    var col = df.Columns[name];\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"does not exist\") || ex.ParamName == \"columnName\")\n{\n    // handle missing column\n}","preventionTips":["Validate required column names against the loaded schema at pipeline start.","Watch casing and whitespace in headers; trim/normalize names on load.","Use IndexOf/TryGetColumnIndex instead of the throwing indexer in probe paths."],"tags":["dataframe","invalid-column-name","argument-exception","dotnet"],"backgroundTag":"entity-not-found","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"}