{"record":{"id":"477037b3b24b2398","repo":"dotnet/machinelearning","slug":"value-cannot-be-null-parameter-name-477037","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'name')","messagePattern":"Value cannot be null\\. \\(Parameter 'name'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.DataView/DataViewSchema.cs","lineNumber":38,"sourceCode":"    {\n        private readonly Column[] _columns;\n        private readonly Dictionary<string, int> _nameMap;\n\n        /// <summary>\n        /// Number of columns in the schema.\n        /// </summary>\n        public int Count => _columns.Length;\n\n        /// <summary>\n        /// Get the column by name. Throws an exception if such column does not exist.\n        /// Note that if multiple columns exist with the same name, the one with the biggest index is returned.\n        /// The other columns are considered 'hidden', and only accessible by their index.\n        /// </summary>\n        public Column this[string name]\n        {\n            get\n            {\n                if (string.IsNullOrEmpty(name)) throw new ArgumentNullException(nameof(name));\n                if (!_nameMap.TryGetValue(name, out int col))\n                    throw new ArgumentOutOfRangeException(nameof(name), $\"Column '{name}' not found\");\n                return _columns[col];\n            }\n        }\n\n        /// <summary>\n        /// Get the column by index.\n        /// </summary>\n        public Column this[int columnIndex]\n        {\n            get\n            {\n                if (!(0 <= columnIndex && columnIndex < _columns.Length))\n                    throw new ArgumentOutOfRangeException(nameof(columnIndex));\n                return _columns[columnIndex];\n            }\n        }","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.DataView/DataViewSchema.cs#L20-L56","documentation":"DataViewSchema's string indexer looks up a column by name using an internal name map. Null or empty names are rejected with ArgumentNullException('name') before the lookup, since a null/empty column name can never exist in the schema.","triggerScenarios":"Accessing schema[name] where name is null or the empty string, often from an unvalidated variable or an API that returned a null column name.","commonSituations":"Copy-pasting a variable name into the indexer instead of the literal; upstream code returning null column names; deserialization producing null metadata names.","solutions":["Check string.IsNullOrEmpty(name) before indexing the schema","Use GetColumnOrNull(name, out col) to safely probe for a column without throwing","Fix the upstream source that produced a null/empty column name"],"exampleFix":"// before\nvar col = schema[name];\n// after\nif (!schema.GetColumnOrNull(name, out var col))\n    throw new ArgumentException($\"Column '{name}' not found\");","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(name)) throw new ArgumentException(\"Column name must be non-empty\");\nvar col = schema[name];","typeGuard":null,"tryCatchPattern":"try { var col = schema[name]; }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"name\")\n{ /* null/empty name — fix source of the name */ }","preventionTips":["Never pass user/config strings to the schema indexer without an IsNullOrEmpty check","Prefer GetColumnOrNull for probing unknown column names","Validate column names at configuration load time"],"tags":["schema","null-argument","dataview"],"backgroundTag":"null-argument","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}