{"record":{"id":"5e6d47b4c9850f6f","repo":"dotnet/machinelearning","slug":"the-data-type-labeltype-is-not-handled-current","errorCode":null,"errorMessage":"The data type '{labelType}' is not handled currently.","messagePattern":"The data type '(.+?)' is not handled currently\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.CodeGenerator/Utils.cs","lineNumber":171,"sourceCode":"            {\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);\n                case Microsoft.ML.Data.DataKind.Int32:\n                    return typeof(int);\n                case Microsoft.ML.Data.DataKind.UInt32:\n                    return typeof(uint);\n                case Microsoft.ML.Data.DataKind.Int64:\n                    return typeof(long);\n                case Microsoft.ML.Data.DataKind.UInt64:\n                    return typeof(ulong);\n                default:\n                    throw new ArgumentException($\"The data type '{labelType}' is not handled currently.\");\n            }\n        }\n\n        internal static void WriteOutputToFiles(string fileContent, string fileName, string outPutBaseDir)\n        {\n            if (!Directory.Exists(outPutBaseDir))\n            {\n                Directory.CreateDirectory(outPutBaseDir);\n            }\n            File.WriteAllText($\"{outPutBaseDir}/{fileName}\", fileContent);\n        }\n\n        internal static string FormatCode(string trainProgramCSFileContent)\n        {\n            //Format\n            var tree = CSharpSyntaxTree.ParseText(trainProgramCSFileContent);\n            var syntaxNode = tree.GetRoot();\n            trainProgramCSFileContent = Formatter.Format(syntaxNode, new AdhocWorkspace()).ToFullString();","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.CodeGenerator/Utils.cs#L153-L189","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: date label column passes through unchanged\npipeline.Append(mlContext.Regression.Trainers.Sdca(labelColumnName: \"OrderDate\"));\n// after: convert label to a supported numeric kind first\nvar converted = mlContext.Transforms.Conversion.ConvertType(\"OrderDateNum\", \"OrderDate\", outputKind: DataKind.Int32)\n    .Append(pipeline);","handlingStrategy":"validation","validationCode":"var colType = schema.GetColumnOrNull(labelColumn)?.Value.Type;\nvar ok = colType is NumberDataViewType ||\n         colType.RawType == typeof(uint) || colType.RawType == typeof(long) ||\n         colType.RawType == typeof(ulong);\nif (!ok) throw new InvalidOperationException($\"Label column '{labelColumn}' has unsupported kind {colType}\");","typeGuard":"static bool HasSupportedLabelType(DataViewSchema.Column col) =>\n    col.Type is NumberDataViewType n &&\n    (n == NumberDataViewType.Single || n == NumberDataViewType.Double ||\n     n == NumberDataViewType.Int32 || n == NumberDataViewType.UInt32 ||\n     n == NumberDataViewType.Int64 || n == NumberDataViewType.UInt64);","tryCatchPattern":"try\n{\n    var clrType = Utils.GetCSharpType(labelType);\n}\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"The data type\"))\n{\n    // fall back to object / abort codegen for this column\n    clrType = typeof(object);\n}","preventionTips":["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."],"tags":["mlnet","datakind","type-mapping","codegen"],"backgroundTag":"unsupported-dtype","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"}