{"record":{"id":"d47a1314509fc87d","repo":"dotnet/machinelearning","slug":"strings-badcolumncast-formatted-with-column-datat-d47a13","errorCode":null,"errorMessage":"Strings.BadColumnCast (formatted with column.DataType, typeof(UInt64))","messagePattern":"Strings\\.BadColumnCast \\(formatted with column\\.DataType, typeof\\(UInt64\\)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/DataFrameColumnCollection.cs","lineNumber":478,"sourceCode":"\n            throw new ArgumentException(string.Format(Strings.BadColumnCast, column.DataType, typeof(string)));\n        }\n\n        /// <summary>\n        /// Gets the <see cref=\"UInt64DataFrameColumn\"/> with the specified <paramref name=\"name\"/>.\n        /// </summary>\n        /// <param name=\"name\">The name of the column</param>\n        /// <returns><see cref=\"UInt64DataFrameColumn\"/>.</returns>\n        /// <exception cref=\"ArgumentException\">A column named <paramref name=\"name\"/> cannot be found, or if the column's type doesn't match.</exception>\n        public UInt64DataFrameColumn GetUInt64Column(string name)\n        {\n            DataFrameColumn column = this[name];\n            if (column is UInt64DataFrameColumn ret)\n            {\n                return ret;\n            }\n\n            throw new ArgumentException(string.Format(Strings.BadColumnCast, column.DataType, typeof(UInt64)));\n        }\n\n        /// <summary>\n        /// Gets the <see cref=\"UInt16DataFrameColumn\"/> with the specified <paramref name=\"name\"/>.\n        /// </summary>\n        /// <param name=\"name\">The name of the column</param>\n        /// <returns><see cref=\"UInt16DataFrameColumn\"/>.</returns>\n        /// <exception cref=\"ArgumentException\">A column named <paramref name=\"name\"/> cannot be found, or if the column's type doesn't match.</exception>\n        public UInt16DataFrameColumn GetUInt16Column(string name)\n        {\n            DataFrameColumn column = this[name];\n            if (column is UInt16DataFrameColumn ret)\n            {\n                return ret;\n            }\n\n            throw new ArgumentException(string.Format(Strings.BadColumnCast, column.DataType, typeof(UInt16)));\n        }","sourceCodeStart":460,"sourceCodeEnd":496,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/DataFrameColumnCollection.cs#L460-L496","documentation":"GetUInt64Column looks up a column by name and returns it only if it is a UInt64DataFrameColumn. If the column exists but has a different element type, the library throws ArgumentException with Strings.BadColumnCast, formatted with the column's actual DataType and typeof(UInt64). This is a deliberate fail-fast instead of a silent invalid cast. Note it also throws if the name is absent (column is null).","triggerScenarios":"Calling DataFrameColumnCollection.GetUInt64Column(name) where the column named 'name' exists but is not a UInt64DataFrameColumn (e.g. it was created as Int64, Double, or String), or where no column with that name exists.","commonSituations":"Reading CSV/JSON data where the column was inferred as Int32/Int64/Double and the code assumes UInt64; schema drift after a data source change; typos in column names that silently resolve to a differently-typed column; mixed-type dataframes built programmatically.","solutions":["Check the column type before calling: if (df.Columns[name].DataType == typeof(ulong)) df.Columns.GetUInt64Column(name);","Use the generic indexer or Convert: df[name] as UInt64DataFrameColumn, or create a converted column via column.Clone / arithmetic conversion APIs if a cast is genuinely needed.","Fix the data loading/parsing so the column is created as UInt64DataFrameColumn (explicit schema when reading files).","Verify the column name spelling and that the intended column exists (this[name] returning null also leads to a throw here)."],"exampleFix":"// before\nvar col = df.Columns.GetUInt64Column(\"Id\"); // throws if inferred as Int64\n\n// after\nif (df.Columns[\"Id\"].DataType != typeof(ulong))\n{\n    df[\"Id\"] = df[\"Id\"].Cast<ulong>(); // or load with explicit schema\n}\nvar col = df.Columns.GetUInt64Column(\"Id\");","handlingStrategy":"type-guard","validationCode":"if (df.Columns[name] is not UInt64DataFrameColumn)\n    throw new InvalidOperationException($\"Column '{name}' is {df.Columns[name]?.DataType?.Name ?? \"missing\"}, expected UInt64\");","typeGuard":"static bool IsUInt64Column(DataFrameColumn c) => c is UInt64DataFrameColumn;","tryCatchPattern":"try { var col = df.Columns.GetUInt64Column(name); }\ncatch (ArgumentException ex) { /* handle wrong/missing column type */ }","preventionTips":["Check DataType before typed getters","Load files with explicit schemas","Use pattern matching (is UInt64DataFrameColumn) instead of getters","Validate column names against df.Columns.Columns collection"],"tags":["dotnet","dataframe","type-mismatch","argument-exception"],"backgroundTag":"type-mismatch","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"}