dotnet/machinelearning · error · System.ArgumentException
Parameter.Count exceeds the number of columns({0}) in the Da
Error message
Parameter.Count exceeds the number of columns({0}) in the DataFrame What it means
After enumerating the appended row's values against the DataFrame's columns, Append checks rowMoveNext; if the row still has values left it throws ArgumentException with Strings.ExceedsNumberOfColumns ('Parameter.Count exceeds the number of columns({0}) in the DataFrame'), naming the `row` parameter. The supplied row has more fields than the DataFrame has columns.
Source
Thrown at src/Microsoft.Data.Analysis/DataFrame.cs:575
value = null;
}
}
if (value != null)
{
value = Convert.ChangeType(value, column.DataType, cultureInfo);
if (value is null)
{
throw new ArgumentException(string.Format(Strings.MismatchedValueType, column.DataType), column.Name);
}
}
cachedObjectConversions.Add(value);
columnMoveNext = columnEnumerator.MoveNext();
rowMoveNext = rowEnumerator.MoveNext();
}
if (rowMoveNext)
{
throw new ArgumentException(string.Format(Strings.ExceedsNumberOfColumns, Columns.Count), nameof(row));
}
// Reset the enumerators
columnEnumerator = ret.Columns.GetEnumerator();
columnMoveNext = columnEnumerator.MoveNext();
rowEnumerator = row.GetEnumerator();
rowMoveNext = rowEnumerator.MoveNext();
int cacheIndex = 0;
while (columnMoveNext && rowMoveNext)
{
DataFrameColumn column = columnEnumerator.Current;
object value = cachedObjectConversions[cacheIndex];
ret.ResizeByOneAndAppend(column, value);
columnMoveNext = columnEnumerator.MoveNext();
rowMoveNext = rowEnumerator.MoveNext();
cacheIndex++;
}
}
while (columnMoveNext)View on GitHub (pinned to 7b76e69cf9)
Solutions
- Ensure each row's keys exactly match df.Columns names — filter or project the row before Append.
- Recreate rows from the current DataFrame schema rather than reusing rows from another DataFrame.
- Catch ArgumentException and log the row's keys vs df.Columns to spot the extra field.
- If extra fields are expected, add the corresponding columns to the DataFrame first (or ignore them explicitly).
Example fix
// before df.Append(rowWithExtraField); // after var trimmed = new DataFrameRow(rowWithExtraField.Where(kv => df.Columns.Contains(kv.Key))); df.Append(trimmed);
Defensive patterns
Strategy: validation
Validate before calling
var extra = row.Where(kv => !df.Columns.Contains(kv.Key)).ToList();
if (extra.Any())
throw new InvalidOperationException($"Row has extra fields: {string.Join(',', extra.Select(kv => kv.Key))}");
df.Append(row); Type guard
bool MatchesSchema(DataFrame df, DataFrameRow row) => row.All(kv => df.Columns.Contains(kv.Key));
Try / catch
try { df.Append(row); }
catch (ArgumentException ex) { logger.LogError(ex, "Row wider than DataFrame ({0} cols)", df.Columns.Count); throw; } Prevention
- Build rows from the current target schema, not from a foreign source
- Explicitly project/drop unknown fields when ingesting evolving file formats
- Add schema tests that append a representative row in CI
When it happens
Trigger: Appending a DataFrameRow created for a wider schema (extra key/value entries) than the target DataFrame; appending after columns were dropped; rows built with both positional and named values.
Common situations: Schema drift between file versions (extra CSV/JSON field); appending rows from an older schema into a trimmed DataFrame; duplicate entries for the same column in the row dictionary.
Related errors
- Column lengths are mismatched
- Exception of type 'System.ArgumentException' was thrown.
- Expected either {0} or {1} to be provided
- Expected a seekable stream
- Decimal separator cannot match the column separator
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/0aa62da4fba707c4.
Report an issue: GitHub.