dotnet/machinelearning · error · System.ArgumentException
Array lengths are mistmached
Error message
Array lengths are mistmached
What it means
Merge requires the retained and supplementary join-key arrays to have the same number of entries — one join column per side per key. When lengths differ it throws ArgumentException(Strings.MismatchedArrayLengths, nameof(retainedJoinColumnNames)); note the resource string reads 'Array lengths are mistmached' (typo included).
Source
Thrown at src/Microsoft.Data.Analysis/DataFrame.Join.cs:183
/// <returns></returns>
public DataFrame Merge<TKey>(DataFrame other, string leftJoinColumn, string rightJoinColumn, string leftSuffix = "_left", string rightSuffix = "_right", JoinAlgorithm joinAlgorithm = JoinAlgorithm.Left)
{
return Merge(other, new[] { leftJoinColumn }, new[] { rightJoinColumn }, leftSuffix, rightSuffix, joinAlgorithm);
}
private static HashSet<long> Merge(DataFrame retainedDataFrame, DataFrame supplementaryDataFrame,
string[] retainedJoinColumnNames, string[] supplemetaryJoinColumnNames,
out PrimitiveDataFrameColumn<long> retainedRowIndices, out PrimitiveDataFrameColumn<long> supplementaryRowIndices,
bool isInner = false, bool calculateIntersection = false)
{
if (retainedJoinColumnNames == null)
throw new ArgumentNullException(nameof(retainedJoinColumnNames));
if (supplemetaryJoinColumnNames == null)
throw new ArgumentNullException(nameof(supplemetaryJoinColumnNames));
if (retainedJoinColumnNames.Length != supplemetaryJoinColumnNames.Length)
throw new ArgumentException(Strings.MismatchedArrayLengths, nameof(retainedJoinColumnNames));
Dictionary<long, ICollection<long>> occurrences = GetOccurences(retainedDataFrame, supplementaryDataFrame,
retainedJoinColumnNames, supplemetaryJoinColumnNames, out HashSet<long> supplementaryJoinColumnsNullIndices);
return PerformMerging(retainedDataFrame, retainedJoinColumnNames, occurrences, supplementaryJoinColumnsNullIndices,
out retainedRowIndices, out supplementaryRowIndices, isInner, calculateIntersection);
}
private static Dictionary<long, ICollection<long>> GetOccurences(DataFrame retainedDataFrame, DataFrame supplementaryDataFrame,
string[] retainedJoinColumnNames, string[] supplemetaryJoinColumnNames, out HashSet<long> supplementaryJoinColumnsNullIndices)
{
supplementaryJoinColumnsNullIndices = new HashSet<long>();
// Get occurrences of values in columns used for join in the retained and supplementary dataframes
Dictionary<long, ICollection<long>> occurrences = null;
Dictionary<long, long> retainedIndicesReverseMapping = null;
View on GitHub (pinned to 7b76e69cf9)
Solutions
- Make both arrays the same length, pairing columns positionally for each join key
- Include every composite-key column on both sides
- Validate lengths and contents exist in each DataFrame before merging
- Catch ArgumentException and report which join specification was mismatched
Example fix
// before
df.Merge(other, new[] { "Id" }, new[] { "Id", "TenantId" });
// after
df.Merge(other, new[] { "Id", "TenantId" }, new[] { "Id", "TenantId" }); Defensive patterns
Strategy: validation
Validate before calling
if (leftKeys == null || rightKeys == null || leftKeys.Length != rightKeys.Length)
throw new InvalidOperationException("Join key arrays must have equal length"); Try / catch
try { return df.Merge(other, leftKeys, rightKeys); } catch (ArgumentException ex) when (ex.Message.Contains("mistmached")) { throw new InvalidOperationException("Composite join keys must be paired on both sides", ex); } Prevention
- Build both key arrays from a single shared definition
- Verify each key column exists in both DataFrames
- Write a small wrapper around Merge that validates pairing before delegating
When it happens
Trigger: Calling Merge with retainedJoinColumnNames.Length != supplemetaryJoinColumnNames.Length, e.g. df.Merge(other, new[]{"Id"}, new[]{"Id","TenantId"}).
Common situations: Joining composite keys where one side lists fewer columns; building the key arrays from different config sources that drifted; renaming a column on one side so it was dropped from one array.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- 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
- Value cannot be null. (Parameter 'retainedJoinColumnNames')
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/cb7e3350658475c3.
Report an issue: GitHub.