{"record":{"id":"bc9ac072b055c2ed","repo":"dotnet/machinelearning","slug":"input-cannot-be-empty-parameter-input","errorCode":null,"errorMessage":"input cannot be empty (Parameter 'input')","messagePattern":"input cannot be empty \\(Parameter 'input'\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.CodeGenerator/Utils.cs","lineNumber":143,"sourceCode":"                var f = val as bool?;\n                return f.GetValueOrDefault() ? \"true\" : \"false\";\n            }\n\n            return val.ToString();\n        }\n\n        internal static string Normalize(string input)\n        {\n            //check if first character is int\n            if (!string.IsNullOrEmpty(input) && int.TryParse(input.Substring(0, 1), out int val))\n            {\n                input = \"_\" + input;\n                return Normalize(input);\n            }\n            switch (input)\n            {\n                case null: throw new ArgumentNullException(nameof(input));\n                case \"\": throw new ArgumentException($\"{nameof(input)} cannot be empty\", nameof(input));\n                default:\n                    var sanitizedInput = Sanitize(input);\n                    return sanitizedInput.First().ToString().ToUpper() + sanitizedInput.Substring(1);\n            }\n        }\n\n        internal static Type GetCSharpType(DataKind labelType)\n        {\n            switch (labelType)\n            {\n                case Microsoft.ML.Data.DataKind.String:\n                    return typeof(string);\n                case Microsoft.ML.Data.DataKind.Boolean:\n                    return typeof(bool);\n                case Microsoft.ML.Data.DataKind.Single:\n                    return typeof(float);\n                case Microsoft.ML.Data.DataKind.Double:\n                    return typeof(double);","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.CodeGenerator/Utils.cs#L125-L161","documentation":"Utils.Normalize throws ArgumentException with message 'input cannot be empty' when given the empty string, because an empty string cannot become a valid C# identifier. Note the loop earlier prefixes '_' only for inputs starting with non-letter characters (digits can't yield \"\"), so empty input falls straight into the switch case.","triggerScenarios":"Calling Utils.Normalize(\"\") directly, or passing a PipelineNode/schema item whose name is the empty string (e.g. a column with a blank header or an empty name field) through the code generation path.","commonSituations":"CSV/TSV files with an empty header cell; whitespace-only headers that get trimmed to empty elsewhere; manually constructed metadata with empty names.","solutions":["Validate the name is non-empty (and not just whitespace) before invoking code generation.","Provide a default/fallback identifier when the source name is empty.","Fix the data source headers so no column has a blank name.","Catch ArgumentException and substitute a placeholder like \"Column1\"."],"exampleFix":"// before\nvar identifier = Utils.Normalize(header);\n// after\nif (string.IsNullOrWhiteSpace(header)) header = \"Column\" + i;\nvar identifier = Utils.Normalize(header);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(header))\n    header = \"Column\" + index; // assign fallback before Normalize\nvar identifier = Utils.Normalize(header);","typeGuard":"static bool IsNonEmptyName(string s) => !string.IsNullOrWhiteSpace(s);","tryCatchPattern":"try\n{\n    identifier = Utils.Normalize(header);\n}\ncatch (ArgumentException ex) when (ex.ParamName == \"input\")\n{\n    identifier = \"Column_\" + index;\n}","preventionTips":["Trim and check headers at load time; reject or rename empty ones.","Never pass user-edited names straight into identifier generation.","Generate deterministic placeholder names for blank headers.","Add data-import tests covering files with blank header cells."],"tags":["csharp","empty-string","identifier","codegen"],"backgroundTag":"empty-required-field","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"}