dotnet/machinelearning · error · ArgumentException

String.Format(Strings.MultipleMismatchedValueType, typeof(lo

Error message

String.Format(Strings.MultipleMismatchedValueType, typeof(long), typeof(int), typeof(bool))

What it means

When cloning a StringDataFrameColumn with mapIndices, the map indices column must be PrimitiveDataFrameColumn of long, int, or bool. Any other DataType throws ArgumentException with MultipleMismatchedValueType listing the three accepted types.

Source

Thrown at src/Microsoft.Data.Analysis/DataFrameColumns/StringDataFrameColumn.cs:307

        {
            StringDataFrameColumn ret = new StringDataFrameColumn(Name, Length);
            for (long i = 0; i < Length; i++)
                ret[i] = this[i];

            for (long i = 0; i < numberOfNullsToAppend; i++)
                ret.Append(null);

            return ret;
        }

        protected override DataFrameColumn CloneImplementation(DataFrameColumn mapIndices, bool invertMapIndices = false, long numberOfNullsToAppend = 0)
        {
            StringDataFrameColumn clone;
            if (!(mapIndices is null))
            {
                Type dataType = mapIndices.DataType;
                if (dataType != typeof(long) && dataType != typeof(int) && dataType != typeof(bool))
                    throw new ArgumentException(String.Format(Strings.MultipleMismatchedValueType, typeof(long), typeof(int), typeof(bool)), nameof(mapIndices));
                if (mapIndices.DataType == typeof(long))
                    clone = CloneImplementation(mapIndices as PrimitiveDataFrameColumn<long>, invertMapIndices);
                else if (dataType == typeof(int))
                    clone = CloneImplementation(mapIndices as PrimitiveDataFrameColumn<int>, invertMapIndices);
                else
                    clone = CloneImplementation(mapIndices as PrimitiveDataFrameColumn<bool>);

                for (long i = 0; i < numberOfNullsToAppend; i++)
                    clone.Append(null);
            }
            else
            {
                clone = Clone(numberOfNullsToAppend);
            }

            return clone;
        }

View on GitHub (pinned to 7b76e69cf9)

Solutions

  1. Cast mapIndices to PrimitiveDataFrameColumn<long> (or int/bool) before calling Clone
  2. Use a bool mask column (PrimitiveDataFrameColumn<bool>) for filtering
  3. Create the indices column explicitly with long element type
  4. Convert the indices column via Elementwise conversion before cloning

Example fix

// before
column.Clone(floatIndices);
// after
var longIndices = new PrimitiveDataFrameColumn<long>("indices", floatIndices.Length);
for (long i = 0; i < floatIndices.Length; i++) longIndices[i] = (long)floatIndices[i];
column.Clone(longIndices);
Defensive patterns

Strategy: validation

Validate before calling

var t = mapIndices.DataType;
if (t != typeof(long) && t != typeof(int) && t != typeof(bool))
    throw new ArgumentException("mapIndices must be long, int, or bool");

Type guard

bool IsValidMapIndices(DataFrameColumn c) =>
    c is PrimitiveDataFrameColumn<long> || c is PrimitiveDataFrameColumn<int> || c is PrimitiveDataFrameColumn<bool>;

Try / catch

try { var clone = column.Clone(mapIndices); } catch (ArgumentException) { /* convert indices type and retry */ }

Prevention

When it happens

Trigger: Calling Clone(mapIndices) where mapIndices is a PrimitiveDataFrameColumn of e.g. float, double, decimal, or DateTime.

Common situations: Building a selection index with the wrong numeric type; deriving indices from computations that produced doubles; using float indices read from CSV parsing.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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