dotnet/machinelearning · error · System.NotSupportedException

kind

Error message

kind

What it means

CreateColumn maps a column Type (the 'kind') to a concrete DataFrameColumn implementation. If the kind is not one of the supported primitive types, string, or DateTime, it throws NotSupportedException(nameof(kind)), so the runtime message is literally "kind". It means CSV type inference/dataTypes requested a column type the library cannot construct.

Source

Thrown at src/Microsoft.Data.Analysis/DataFrame.IO.cs:345

            else if (kind == typeof(uint))
            {
                ret = new UInt32DataFrameColumn(columnName);
            }
            else if (kind == typeof(ulong))
            {
                ret = new UInt64DataFrameColumn(columnName);
            }
            else if (kind == typeof(ushort))
            {
                ret = new UInt16DataFrameColumn(columnName);
            }
            else if (kind == typeof(DateTime))
            {
                ret = new DateTimeDataFrameColumn(columnName);
            }
            else
            {
                throw new NotSupportedException(nameof(kind));
            }
            return ret;
        }

        private static DataFrameColumn CreateColumn(Type kind, string[] columnNames, int columnIndex)
        {
            return CreateColumn(kind, GetColumnName(columnNames, columnIndex));
        }

        private static DataFrame ReadCsvLinesIntoDataFrame(WrappedStreamReaderOrStringReader wrappedReader,
                                char separator = ',', bool header = true,
                                string[] columnNames = null, Type[] dataTypes = null,
                                long numberOfRowsToRead = -1, int guessRows = 10, bool addIndexColumn = false,
                                bool renameDuplicatedColumns = false,
                                CultureInfo cultureInfo = null, Func<IEnumerable<string>, Type> guessTypeFunction = null)
        {
            if (cultureInfo == null)
            {

View on GitHub (pinned to 7b76e69cf9)

Solutions

  1. Use only supported column types: primitives (bool, byte, char, decimal, double, float, int, long, sbyte, short, uint, ulong, ushort), string, and DateTime
  2. Fix the dataTypes array entries passed to LoadCsv to supported types
  3. Fix the custom guessTypeFunction so it returns only supported types
  4. Upgrade the Microsoft.Data.Analysis package if you need a type added in a newer version

Example fix

// before
var df = DataFrame.LoadCsv(stream, dataTypes: new[] { typeof(Guid) });
// after
var df = DataFrame.LoadCsv(stream, dataTypes: new[] { typeof(string) }); // then convert as needed
Defensive patterns

Strategy: type-guard

Validate before calling

static readonly HashSet<Type> Supported = new HashSet<Type> { typeof(bool), typeof(byte), typeof(char), typeof(decimal), typeof(double), typeof(float), typeof(int), typeof(long), typeof(sbyte), typeof(short), typeof(uint), typeof(ulong), typeof(ushort), typeof(string), typeof(DateTime) };
bool ok = dataTypes == null || dataTypes.All(Supported.Contains);

Type guard

bool IsSupportedColumnType(Type t) => t == typeof(string) || t == typeof(DateTime) || (t.IsPrimitive && t != typeof(IntPtr) && t != typeof(UIntPtr));

Try / catch

try { return DataFrame.LoadCsv(stream, dataTypes: dataTypes); } catch (NotSupportedException) { return DataFrame.LoadCsv(stream, dataTypes: dataTypes.Select(t => typeof(string)).ToArray()); }

Prevention

When it happens

Trigger: Passing a dataTypes entry (or a custom guessTypeFunction result) that is not a supported column type — e.g. typeof(Guid), typeof(short) if unsupported in this version, nullable variants, or any arbitrary Type — into LoadCsv/LoadCsvFromString, which reaches CreateColumn via column/CreateColumn.

Common situations: Users supply dataTypes: new[]{typeof(object)} or business types; a custom guessTypeFunction returns an unsupported Type; a type supported in newer Microsoft.Data.Analysis versions is used against an older package.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11). Data as JSON: /api/errors/2bb41df161592248. Report an issue: GitHub.