dotnet/machinelearning · error · NotSupportedException
Type is T
Error message
Type is T
What it means
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.
Source
Thrown at src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.cs:856
{
return NumberDataViewType.UInt64;
}
else if (typeof(T) == typeof(ushort))
{
return NumberDataViewType.UInt16;
}
// The following 2 implementations are not ideal, but IDataView doesn't support
// these types
else if (typeof(T) == typeof(char))
{
return NumberDataViewType.UInt16;
}
else if (typeof(T) == typeof(decimal))
{
return NumberDataViewType.Double;
}
throw new NotSupportedException("Type is " + typeof(T).Name);
}
protected internal override Delegate GetDataViewGetter(DataViewRowCursor cursor)
{
// special cases for types that have NA values
if (typeof(T) == typeof(float))
{
return CreateSingleValueGetterDelegate(cursor, (PrimitiveDataFrameColumn<float>)(object)this);
}
else if (typeof(T) == typeof(double))
{
return CreateDoubleValueGetterDelegate(cursor, (PrimitiveDataFrameColumn<double>)(object)this);
}
// special cases for types not supported
else if (typeof(T) == typeof(char))
{
return CreateCharValueGetterDelegate(cursor, (PrimitiveDataFrameColumn<char>)(object)this);
}View on GitHub (pinned to 7b76e69cf9)
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
Example fix
// before
var col = new PrimitiveDataFrameColumn<ushort>("u");
var df = new DataFrame(col); // NotSupportedException
// after
var col = new PrimitiveDataFrameColumn<long>("u");
for (long i = 0; i < ushortCol.Length; i++) col.Append(ushortCol[i]);
var df = new DataFrame(col); Defensive patterns
Strategy: type-guard
Validate before calling
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 */; Type guard
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);
Try / catch
try { var df = new DataFrame(column); ReadViaDataView(df); } catch (NotSupportedException) { /* convert column to supported type */ } Prevention
- 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
When it happens
Trigger: 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).
Common situations: Using unsigned or narrower integer types as column storage, or custom unmanaged structs, then consuming the DataFrame through ML.NET DataView APIs.
Related errors
- Cannot cast elements of column '{0}' type of {1} to type {2}
- Expected value to be of type {0}
- String.Format(Strings.MismatchedColumnValueType, this.DataTy
- Strings.BadColumnCast (formatted with column.DataType, typeo
- Strings.BadColumnCast (formatted with column.DataType, typeo
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/d087c8ffa4dc821f.
Report an issue: GitHub.