{"record":{"id":"7adee3c592c2c936","repo":"dotnet/machinelearning","slug":"provided-label-column-cannot-be-null","errorCode":null,"errorMessage":"Provided label column cannot be null","messagePattern":"Provided label column cannot be null","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"critical","filePath":"src/Microsoft.ML.AutoML/Utils/UserInputValidationUtil.cs","lineNumber":160,"sourceCode":"            if (duplicateColName != null)\n            {\n                throw new ArgumentException($\"Duplicate column name {duplicateColName} is present in two or more distinct properties of provided column information\", nameof(columnInformation));\n            }\n        }\n\n        private static void ValidateColumnInfoEnumerationProperty(IEnumerable<string> columns, string columnPurpose)\n        {\n            if (columns?.Contains(null) == true)\n            {\n                throw new ArgumentException($\"Null column string was specified as {columnPurpose} in column information\");\n            }\n        }\n\n        private static void ValidateLabelColumn(string labelColumn)\n        {\n            if (labelColumn == null)\n            {\n                throw new ArgumentException(\"Provided label column cannot be null\");\n            }\n        }\n\n        private static void ValidatePath(string path)\n        {\n            if (path == null)\n            {\n                throw new ArgumentNullException(nameof(path), \"Provided path cannot be null\");\n            }\n\n            var fileInfo = new FileInfo(path);\n\n            if (!fileInfo.Exists)\n            {\n                throw new ArgumentException($\"File '{path}' does not exist\", nameof(path));\n            }\n\n            if (fileInfo.Length == 0)","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.AutoML/Utils/UserInputValidationUtil.cs#L142-L178","documentation":"Thrown by UserInputValidationUtil.ValidateLabelColumn when the label column name supplied to an AutoML API (experiment execution or column inference) is null. Every supervised AutoML task requires an identified label column, so a null name is rejected with an ArgumentException (note: not ArgumentNullException despite the null check).","triggerScenarios":"Calling ValidateInferColumnsArgs or ValidateColumnInformation paths with labelColumn = null, e.g. experiment.Execute(trainData, null, ...) or ColumnInformation with LabelColumnName left null where required.","commonSituations":"Relying on a default label column name that does not exist so the variable resolved to null; passing the wrong property from a config object; constructing ColumnInformation without setting LabelColumnName for APIs that require it.","solutions":["Supply the actual label column name, e.g. experiment.Execute(data, nameof(ModelInput.Label), \"A\")","Set ColumnInformation.LabelColumnName to a non-null column present in the schema","Guard the label variable with a null/whitespace check before invoking the API"],"exampleFix":"// before\nstring labelCol = config.Label; // null when config lacks it\nvar result = experiment.Execute(trainData, labelCol, \"A\");\n\n// after\nstring labelCol = config.Label ?? nameof(ModelInput.Label);\nArgumentException.ThrowIfNullOrEmpty(labelCol);\nvar result = experiment.Execute(trainData, labelCol, \"A\");","handlingStrategy":"type-guard","validationCode":"if (string.IsNullOrEmpty(labelColumnName)) throw new InvalidOperationException(\"Label column name is required\");","typeGuard":"static bool HasLabel(ColumnInformation c) => !string.IsNullOrEmpty(c?.LabelColumnName);","tryCatchPattern":"try { var r = experiment.Execute(data, label, \"A\"); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"label column cannot be null\")) { /* prompt user / load default label column */ }","preventionTips":["Always reference the label via nameof(ModelInput.Label) so it cannot resolve to null","Validate config objects (label present, non-empty) at startup","Set ColumnInformation.LabelColumnName explicitly in every experiment setup"],"tags":["dotnet","mlnet","automl","label-column","null-argument"],"backgroundTag":"missing-required-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"}