dotnet/machinelearning · error · ArgumentNullException
Value cannot be null. (Parameter 'input')
Error message
Value cannot be null. (Parameter 'input')
What it means
Utils.Normalize converts a string into a valid C# identifier (sanitizing, prefixing, capitalizing). Passing null reaches the switch on input and throws ArgumentNullException('input'). The library requires a non-null string because it must produce a valid identifier name for generated code.
Source
Thrown at src/Microsoft.ML.CodeGenerator/Utils.cs:142
{
var f = val as bool?;
return f.GetValueOrDefault() ? "true" : "false";
}
return val.ToString();
}
internal static string Normalize(string input)
{
//check if first character is int
if (!string.IsNullOrEmpty(input) && int.TryParse(input.Substring(0, 1), out int val))
{
input = "_" + input;
return Normalize(input);
}
switch (input)
{
case null: throw new ArgumentNullException(nameof(input));
case "": throw new ArgumentException($"{nameof(input)} cannot be empty", nameof(input));
default:
var sanitizedInput = Sanitize(input);
return sanitizedInput.First().ToString().ToUpper() + sanitizedInput.Substring(1);
}
}
internal static Type GetCSharpType(DataKind labelType)
{
switch (labelType)
{
case Microsoft.ML.Data.DataKind.String:
return typeof(string);
case Microsoft.ML.Data.DataKind.Boolean:
return typeof(bool);
case Microsoft.ML.Data.DataKind.Single:
return typeof(float);
case Microsoft.ML.Data.DataKind.Double:View on GitHub (pinned to 7b76e69cf9)
Solutions
- Ensure the name source is non-null before calling Normalize; supply a fallback name when the column/metadata name is missing.
- Check your input data headers — replace empty/null headers with valid names.
- If calling Normalize directly, guard with string.IsNullOrWhiteSpace before the call.
- Catch ArgumentNullException and substitute a generated placeholder name.
Example fix
// before var identifier = Utils.Normalize(columnName); // after var identifier = Utils.Normalize(columnName ?? "Column_" + index);
Defensive patterns
Strategy: validation
Validate before calling
if (name is null)
throw new InvalidOperationException("Column name was null; check data source headers");
var identifier = Utils.Normalize(name); Type guard
static bool IsNormalizable(string s) => !string.IsNullOrEmpty(s);
Try / catch
try
{
identifier = Utils.Normalize(rawName);
}
catch (ArgumentNullException)
{
identifier = "UnnamedColumn";
} Prevention
- Ensure data files have no missing/blank header cells.
- Coalesce null names to defaults before any codegen step.
- Validate schema column names during data load, not at generation time.
- Prefer string.IsNullOrWhiteSpace checks over null-only checks.
When it happens
Trigger: Calling Utils.Normalize(null) directly, or indirectly when a column/metadata name used to derive an identifier is null (e.g. a schema column with null name passed through code generation helpers that call Normalize).
Common situations: Data files with missing/blank header names producing null column names; programmatic PipelineNode/slot-name construction where the name field was never set; codegen invoked on a schema whose text metadata is absent.
Related errors
- input cannot be empty (Parameter 'input')
- columns
- rawType
- throw new ArgumentNullException(nameof(ids));
- throw new ArgumentNullException(nameof(tokenIds));
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/66f0ee82b3aec063.
Report an issue: GitHub.