dotnet/machinelearning · error · NotSupportedException

TKey

Error message

TKey

What it means

GetGroupedOccurrences/multimap indexing only supports grouping keys (TKey) of type string or byte[]; any other key type reaches a fallthrough that throws NotSupportedException(nameof(TKey)). The message is literally 'TKey', telling you the generic key type argument is not supported.

Source

Thrown at src/Microsoft.Data.Analysis/DataFrameColumns/ArrowStringDataFrameColumn.cs:519

                        if (containsKey)
                        {
                            values.Add(i);
                        }
                        else
                        {
                            multimap.Add(str, new List<long>() { i });
                        }
                    }
                    else
                    {
                        nullIndices.Add(i);
                    }
                }
                return multimap as Dictionary<TKey, ICollection<long>>;
            }
            else
            {
                throw new NotSupportedException(nameof(TKey));
            }
        }

        /// <inheritdoc/>
        public ArrowStringDataFrameColumn FillNulls(string value, bool inPlace = false)
        {
            if (value == null)
            {
                throw new ArgumentException(nameof(value));
            }
            if (inPlace)
            {
                /* For now throw an exception if inPlace = true. Need to investigate if Apache Arrow
                 * format supports filling nulls for variable length arrays
                 */
                throw new NotSupportedException();
            }

View on GitHub (pinned to 7b76e69cf9)

Solutions

  1. Use TKey = string and convert your key values with ToString().
  2. Use TKey = byte[] if your keys are binary.
  3. Hash/encode the key into a string yourself before grouping.
  4. Add a runtime check that TKey is string or byte[] before calling.

Example fix

// before
col.GetGroupedOccurrences<int>(other);
// after
col.GetGroupedOccurrences<string>(other); // keys converted to strings first
Defensive patterns

Strategy: type-guard

Validate before calling

if (typeof(TKey) != typeof(string) && typeof(TKey) != typeof(byte[]))
    throw new NotSupportedException("GetGroupedOccurrences only supports TKey of string or byte[]");

Type guard

bool IsValidGroupKey<TKey>() => typeof(TKey) == typeof(string) || typeof(TKey) == typeof(byte[]);

Prevention

When it happens

Trigger: Calling GetGroupedOccurrences<TKey>(other) with TKey = int, Guid, DateTime, etc. — anything besides string or byte[].

Common situations: Grouping rows by a numeric or date key column; generic helper code forwarding an arbitrary key type into GetGroupedOccurrences.

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/13ec04fd0d157314. Report an issue: GitHub.