dotnet/machinelearning · error · ArgumentException
The data type '{labelType}' is not handled currently.
Error message
The data type '{labelType}' is not handled currently. What it means
Utils.GetCSharpType maps a Microsoft.ML.Data.DataKind label/column type to the corresponding C# System.Type via an exhaustive switch. Hitting the default branch means the DataKind has no C# mapping implemented, so it throws this ArgumentException. It indicates an unhandled DataView type in the label-column generation path.
Source
Thrown at src/Microsoft.ML.CodeGenerator/Utils.cs:171
{
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:
return typeof(double);
case Microsoft.ML.Data.DataKind.Int32:
return typeof(int);
case Microsoft.ML.Data.DataKind.UInt32:
return typeof(uint);
case Microsoft.ML.Data.DataKind.Int64:
return typeof(long);
case Microsoft.ML.Data.DataKind.UInt64:
return typeof(ulong);
default:
throw new ArgumentException($"The data type '{labelType}' is not handled currently.");
}
}
internal static void WriteOutputToFiles(string fileContent, string fileName, string outPutBaseDir)
{
if (!Directory.Exists(outPutBaseDir))
{
Directory.CreateDirectory(outPutBaseDir);
}
File.WriteAllText($"{outPutBaseDir}/{fileName}", fileContent);
}
internal static string FormatCode(string trainProgramCSFileContent)
{
//Format
var tree = CSharpSyntaxTree.ParseText(trainProgramCSFileContent);
var syntaxNode = tree.GetRoot();
trainProgramCSFileContent = Formatter.Format(syntaxNode, new AdhocWorkspace()).ToFullString();View on GitHub (pinned to 7b76e69cf9)
Solutions
- Change the label column to a supported type (cast to Single/Double/Int32/UInt32/Int64/UInt64 as appropriate) before code generation.
- Upgrade Microsoft.ML.CodeGenerator to a version whose GetCSharpType covers your DataKind.
- Inspect the label column's schema (schema.GetColumnOrNull(label).Value.Type) before generating and reject unsupported kinds early.
- If you own the source, extend the switch to map the missing DataKind.
Example fix
// before: date label column passes through unchanged
pipeline.Append(mlContext.Regression.Trainers.Sdca(labelColumnName: "OrderDate"));
// after: convert label to a supported numeric kind first
var converted = mlContext.Transforms.Conversion.ConvertType("OrderDateNum", "OrderDate", outputKind: DataKind.Int32)
.Append(pipeline); Defensive patterns
Strategy: validation
Validate before calling
var colType = schema.GetColumnOrNull(labelColumn)?.Value.Type;
var ok = colType is NumberDataViewType ||
colType.RawType == typeof(uint) || colType.RawType == typeof(long) ||
colType.RawType == typeof(ulong);
if (!ok) throw new InvalidOperationException($"Label column '{labelColumn}' has unsupported kind {colType}"); Type guard
static bool HasSupportedLabelType(DataViewSchema.Column col) =>
col.Type is NumberDataViewType n &&
(n == NumberDataViewType.Single || n == NumberDataViewType.Double ||
n == NumberDataViewType.Int32 || n == NumberDataViewType.UInt32 ||
n == NumberDataViewType.Int64 || n == NumberDataViewType.UInt64); Try / catch
try
{
var clrType = Utils.GetCSharpType(labelType);
}
catch (ArgumentException ex) when (ex.Message.StartsWith("The data type"))
{
// fall back to object / abort codegen for this column
clrType = typeof(object);
} Prevention
- Inspect the label column's DataView type before running AutoML/codegen.
- Convert date, bool, and string labels to numeric kinds up front.
- Keep Microsoft.ML.CodeGenerator current with your Microsoft.ML version.
- Document supported label types for your training datasets.
When it happens
Trigger: Code generation encounters a label column whose DataKind is one not covered by the switch (e.g. DateTime, TimeSpan, Boolean, String or numeric kinds not enumerated) when generating trainer/evaluator code.
Common situations: Datasets with date/time or string label columns fed to AutoML; new DataKind values added in a newer Microsoft.Data.DataView/Microsoft.ML version while an older CodeGenerator switches on them; custom loaders producing exotic column types.
Related errors
- The data type '{dataKind}' is not handled currently.
- The trainer '{trainer}' is not handled currently.
- The trainer '{node.Name}' is not handled currently.
- Bad type in ColumnTypeExtensions.NumberTypeFromType: {type}
- Bad data kind in ColumnTypeExtensions.NumberTypeFromKind: {k
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/5e6d47b4c9850f6f.
Report an issue: GitHub.