dotnet/machinelearning · error · NotSupportedException

Null values are not supported by VBufferDataFrameColumn

Error message

Null values are not supported by VBufferDataFrameColumn

What it means

Guard in VBufferDataFrameColumn.SetValue: this column type stores VBuffer<T> values with no representation for missing data (NullCount is hard-coded to 0), so setting a slot to null is unsupported and throws. The caller must supply a valid (possibly empty) VBuffer<T> instead.

Source

Thrown at src/Microsoft.Data.Analysis/DataFrameColumns/VBufferDataFrameColumn.cs:124

            int bufferIndex = GetBufferIndexContainingRowIndex(startIndex);
            int bufferOffset = (int)(startIndex % MaxCapacity);
            while (ret.Count < length && bufferIndex < _vBuffers.Count)
            {
                for (int i = bufferOffset; ret.Count < length && i < _vBuffers[bufferIndex].Count; i++)
                {
                    ret.Add(_vBuffers[bufferIndex][i]);
                }
                bufferIndex++;
                bufferOffset = 0;
            }
            return ret;
        }

        protected override void SetValue(long rowIndex, object value)
        {
            if (value == null)
            {
                throw new NotSupportedException("Null values are not supported by VBufferDataFrameColumn");
            }
            else if (value is VBuffer<T> vbuffer)
            {
                SetTypedValue(rowIndex, vbuffer);
            }
            else
            {
                throw new ArgumentException(string.Format(Strings.MismatchedValueType, typeof(VBuffer<T>)), nameof(value));
            }
        }

        protected void SetTypedValue(long rowIndex, VBuffer<T> value)
        {
            int bufferIndex = GetBufferIndexContainingRowIndex(rowIndex);
            _vBuffers[bufferIndex][(int)(rowIndex % MaxCapacity)] = value;
        }

        public new VBuffer<T> this[long rowIndex]

View on GitHub (pinned to 7b76e69cf9)

Solutions

  1. Provide a default VBuffer<T>.Empty (or a zero-length buffer) instead of null
  2. Filter or replace nulls in the source before copying
  3. Use DropNulls / null checks on the source column first
  4. Use a supported nullable column type if nulls are truly required

Example fix

// before
column[rowIndex] = null;
// after
column[rowIndex] = VBuffer<T>.Empty;
Defensive patterns

Strategy: type-guard

Validate before calling

if (value is null) throw new NotSupportedException("VBufferDataFrameColumn does not accept nulls");

Type guard

bool IsAssignableVBuffer(object v) => v is VBuffer<T>;

Try / catch

try { column[rowIndex] = value; } catch (NotSupportedException) { column[rowIndex] = VBuffer<T>.Empty; }

Prevention

When it happens

Trigger: Assigning null via the object indexer or SetValue(rowIndex, null); generic row-copy code that passes null through for missing values.

Common situations: Copying from a nullable column with nulls into a VBuffer column; generic DataFrame transformation that doesn't special-case VBuffer columns.

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/10725a1da28525e8. Report an issue: GitHub.