dotnet/efcore · error · ArgumentException
Invalid number of index sort order values: {numValues} value
Error message
Invalid number of index sort order values: {numValues} values were provided, but the index has {numProperties} properties. What it means
Thrown by the IndexAttribute.IsDescending setter when the supplied bool[] length does not equal PropertyNames.Count. The index needs exactly one sort-direction flag per property so each column's order is unambiguous; any mismatch is a modeling configuration error. It surfaces during model building when EF Core (or your own code) processes the attribute.
Source
Thrown at src/EFCore.Abstractions/IndexAttribute.cs:69
public bool IsUnique
{
get => _isUnique ?? false;
set => _isUnique = value;
}
/// <summary>
/// A set of values indicating whether each corresponding index column has descending sort order.
/// </summary>
public bool[]? IsDescending
{
get;
set
{
if (value is not null)
{
if (value.Length != PropertyNames.Count)
{
throw new ArgumentException(
AbstractionsStrings.InvalidNumberOfIndexSortOrderValues(value.Length, PropertyNames.Count), nameof(IsDescending));
}
if (AllDescending)
{
throw new ArgumentException(AbstractionsStrings.CannotSpecifyBothIsDescendingAndAllDescending);
}
}
field = value;
}
}
/// <summary>
/// Whether all index columns have descending sort order.
/// </summary>
public bool AllDescending
{View on GitHub (pinned to dbf9771522)
Solutions
- Make the IsDescending array length equal to the number of properties in the index: one bool per property, in the same order.
- If you want all columns descending, set AllDescending = true instead of IsDescending.
- Double-check the property names list passed to the IndexAttribute constructor and align the IsDescending entries to it.
Example fix
// before
var idx = new IndexAttribute("FirstName", "LastName") { IsDescending = new[] { true } };
// after
var idx = new IndexAttribute("FirstName", "LastName") { IsDescending = new[] { true, false } };
// or, all descending:
var idx2 = new IndexAttribute("FirstName", "LastName") { AllDescending = true }; Defensive patterns
Strategy: validation
Validate before calling
// Before assigning IsDescending, ensure one flag per property
if (isDescendingArray != null && isDescendingArray.Length != indexAttr.PropertyNames.Count)
{
throw new InvalidOperationException(
$"Expected {indexAttr.PropertyNames.Count} sort flags, got {isDescendingArray.Length}.");
}
indexAttr.IsDescending = isDescendingArray; Type guard
static bool IsValidIsDescending(IndexAttribute attr, bool[]? flags)
=> flags is null || flags.Length == attr.PropertyNames.Count; Prevention
- Always size the IsDescending array to match the number of properties passed to the IndexAttribute constructor.
- Prefer AllDescending when every column should descend, to avoid array-length bookkeeping.
- Centralize index attribute construction in a helper that validates flag count.
When it happens
Trigger: Setting indexAttr.IsDescending to an array whose Length != the number of property names passed to the IndexAttribute constructor. For example, constructing new IndexAttribute("A", "B") then assigning IsDescending = new[] { true } (1 flag for a 2-property index).
Common situations: Adding a descending flag to a composite index but forgetting to provide a flag for every column. Refactoring an index from single to composite property and forgetting to extend the IsDescending array. Migrating code from AllDescending to per-column IsDescending.
Related errors
- IsDescending and AllDescending cannot both be specified on t
- The number argument cannot be a negative number.
- The value '{value}' provided for argument '{argumentName}' m
- Cosmos-specific methods can only be used when the context is
- A synchronous store management operation was performed and n
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/6d983ea3785931fc.
Report an issue: GitHub.