dotnet/efcore · error · ArgumentException

values were provided in CreateIndexOperations.IsDescending…

Error message

{numSortOrderProperties} values were provided in CreateIndexOperations.IsDescending, but the operation has {numColumns} columns.

What it means

Thrown by the CreateIndexOperation.Columns setter when IsDescending has already been set and a new columns array is assigned with a different length. Each IsDescending entry corresponds to exactly one column.

Solutions

  1. Set IsDescending AFTER Columns, or reset IsDescending to null before resizing Columns.
  2. Ensure both arrays have the same length, one sort-order flag per column.
  3. When building operations programmatically, set Columns first, then IsDescending.

Example fix

// before
var op = new CreateIndexOperation { Name = "IX_T", Table = "T" };
op.IsDescending = new[] { false, true };
op.Columns = new[] { "A" }; // throws: 2 vs 1

// after
var op = new CreateIndexOperation { Name = "IX_T", Table = "T" };
op.Columns = new[] { "A", "B" };
op.IsDescending = new[] { false, true };
Defensive patterns

Strategy: validation

Validate before calling

static CreateIndexOperation SafeCreateIndex(string name, string table, string[] columns, bool[]? isDescending)
{
    if (isDescending is not null && isDescending.Length != columns.Length)
        throw new ArgumentException("isDescending length must equal columns length.");
    return new CreateIndexOperation { Name = name, Table = table, Columns = columns, IsDescending = isDescending };
}

Prevention

When it happens

Trigger: Assigning operation.Columns after operation.IsDescending, with mismatched lengths. Common in hand-built CreateIndexOperation or reflection/codegen that sets IsDescending first.

Common situations: Custom migration code generators that build operations incrementally. Reflection-based migration construction. Renaming/reordering columns without re-sizing IsDescending.

Related errors


AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11). Data as JSON: /api/errors/88b4504d9b94da7c. Report an issue: GitHub.

Appendix: source

Thrown at src/EFCore.Relational/Migrations/Operations/CreateIndexOperation.cs:43

    /// </summary>
    public virtual string? Schema { get; set; }

    /// <summary>
    ///     The table that contains the index.
    /// </summary>
    public virtual string Table { get; set; } = null!;

    /// <summary>
    ///     The ordered list of column names for the column that make up the index.
    /// </summary>
    public virtual string[] Columns
    {
        get => _columns!;
        set
        {
            if (_isDescending is not null && _isDescending.Length > 0 && value.Length != _isDescending.Length)
            {
                throw new ArgumentException(RelationalStrings.CreateIndexOperationWithInvalidSortOrder(_isDescending.Length, value.Length));
            }

            _columns = value;
        }
    }

    /// <summary>
    ///     Indicates whether or not the index should enforce uniqueness.
    /// </summary>
    public virtual bool IsUnique { get; set; }

    /// <summary>
    ///     A set of values indicating whether each corresponding index column has descending sort order.
    /// </summary>
    public virtual bool[]? IsDescending
    {
        get => _isDescending;
        set

View on GitHub (pinned to 3a2006ef56)