{"record":{"id":"d087c8ffa4dc821f","repo":"dotnet/machinelearning","slug":"type-is-t","errorCode":null,"errorMessage":"Type is T","messagePattern":"Type is T","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.cs","lineNumber":856,"sourceCode":"            {\n                return NumberDataViewType.UInt64;\n            }\n            else if (typeof(T) == typeof(ushort))\n            {\n                return NumberDataViewType.UInt16;\n            }\n            // The following 2 implementations are not ideal, but IDataView doesn't support\n            // these types\n            else if (typeof(T) == typeof(char))\n            {\n                return NumberDataViewType.UInt16;\n            }\n            else if (typeof(T) == typeof(decimal))\n            {\n                return NumberDataViewType.Double;\n            }\n\n            throw new NotSupportedException(\"Type is \" + typeof(T).Name);\n        }\n\n        protected internal override Delegate GetDataViewGetter(DataViewRowCursor cursor)\n        {\n            // special cases for types that have NA values\n            if (typeof(T) == typeof(float))\n            {\n                return CreateSingleValueGetterDelegate(cursor, (PrimitiveDataFrameColumn<float>)(object)this);\n            }\n            else if (typeof(T) == typeof(double))\n            {\n                return CreateDoubleValueGetterDelegate(cursor, (PrimitiveDataFrameColumn<double>)(object)this);\n            }\n            // special cases for types not supported\n            else if (typeof(T) == typeof(char))\n            {\n                return CreateCharValueGetterDelegate(cursor, (PrimitiveDataFrameColumn<char>)(object)this);\n            }","sourceCodeStart":838,"sourceCodeEnd":874,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.cs#L838-L874","documentation":"The column's internal mapping to DataView types (GetColumnDataViewKind / type switch) covers only the supported primitives (byte, short, int, long, float, double, bool, string, decimal etc.); T outside the supported set falls through to a NotSupportedException with message 'Type is <TName>'. Only unmanaged types within the supported list can be backed by a PrimitiveDataFrameColumn in DataView interop.","triggerScenarios":"Creating a PrimitiveDataFrameColumn<T> with an unmanaged T that has no DataView mapping (e.g. char, ushort, sbyte, uint, ulong, custom struct) and then hitting the DataView-conversion path (e.g. attaching the column to a DataFrame and reading it via a DataView cursor).","commonSituations":"Using unsigned or narrower integer types as column storage, or custom unmanaged structs, then consuming the DataFrame through ML.NET DataView APIs.","solutions":["Use supported element types only: byte, short, int, long, float, double, bool, string, decimal, DateTime where applicable","Convert unsupported T columns to a supported type (e.g. ushort -> long) before building the DataFrame","Avoid DataView interop paths for columns of unsupported T"],"exampleFix":"// before\nvar col = new PrimitiveDataFrameColumn<ushort>(\"u\");\nvar df = new DataFrame(col); // NotSupportedException\n// after\nvar col = new PrimitiveDataFrameColumn<long>(\"u\");\nfor (long i = 0; i < ushortCol.Length; i++) col.Append(ushortCol[i]);\nvar df = new DataFrame(col);","handlingStrategy":"type-guard","validationCode":"var supported = new[]{typeof(byte),typeof(short),typeof(int),typeof(long),typeof(float),typeof(double),typeof(bool),typeof(decimal),typeof(string)}; if (!supported.Contains(col.DataType)) /* convert column */;","typeGuard":"bool isDataViewCompatible<T>() where T : unmanaged => typeof(T) == typeof(byte) || typeof(T) == typeof(short) || typeof(T) == typeof(int) || typeof(T) == typeof(long) || typeof(T) == typeof(float) || typeof(T) == typeof(double) || typeof(T) == typeof(bool) || typeof(T) == typeof(decimal);","tryCatchPattern":"try { var df = new DataFrame(column); ReadViaDataView(df); } catch (NotSupportedException) { /* convert column to supported type */ }","preventionTips":["Restrict PrimitiveDataFrameColumn<T> to supported primitives","Convert ushort/uint/ulong/char columns to long before DataFrame interop","Check DataView type mapping support before ML.NET integration"],"tags":["not-supported","data-view","type-mismatch"],"backgroundTag":"operation-not-supported","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"}