elsa-workflows/elsa-core · error · InvalidOperationException
Runtime entity definition
Error message
Runtime entity definition '{definition.Name}' declares {definition.Indexes.Count} indexes, but only {maxIndexedFields} runtime index slots are available. What it means
The number of declared indexes on a runtime entity definition is capped by MaxIndexedFields (from options) and by the physical slot count exposed by RuntimeEntityPersistenceSchemaProvider.IndexedFieldSlotCount — Validate uses the smaller of the two. Exceeding it throws, because the storage layout only materializes that many runtime index columns.
Solutions
- Trim definition.Indexes to the most essential fields so the count fits the limit.
- Raise RuntimeEntityOptions.MaxIndexedFields in configuration, if the physical slot count also allows it.
- Drop low-value indexes (rarely filtered fields) and rely on scans for those queries instead.
Example fix
// before options.MaxIndexedFields = 5; // definition declares 8 indexes // after options.MaxIndexedFields = 10; // or reduce definition.Indexes to 5
Defensive patterns
Strategy: validation
Validate before calling
var max = Math.Min(options.MaxIndexedFields, RuntimeEntityPersistenceSchemaProvider.IndexedFieldSlotCount);
if (definition.Indexes.Count > max) throw new InvalidOperationException($"{definition.Indexes.Count} indexes exceeds limit {max}."); Try / catch
try { validator.Validate(definition); }
catch (InvalidOperationException ex) { logger.LogError(ex, "Too many indexes on {Name}", definition.Name); throw; } Prevention
- Keep MaxIndexedFields configuration in sync with the storage provider's slot count.
- Review index lists whenever a definition gains fields.
- Prefer few high-selectivity indexes over exhaustive indexing.
When it happens
Trigger: Calling Validate where definition.Indexes.Count exceeds min(options.MaxIndexedFields, RuntimeEntityPersistenceSchemaProvider.IndexedFieldSlotCount).
Common situations: Lowering MaxIndexedFields in configuration below a previously valid definition; adding many indexes as a document evolves; a storage provider with fewer physical slots than the definition assumes.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Runtime entity definition
- Runtime entity definition
- Runtime entity definition
- Runtime entity definition name is required.
- Runtime entity instance
AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13).
Data as JSON: /api/errors/bccb0868cf729802.
Report an issue: GitHub.
Appendix: source
Thrown at src/modules/Elsa.Persistence.VNext.Runtime/Services/RuntimeEntityDefinitionValidator.cs:22
namespace Elsa.Persistence.VNext.Runtime.Services;
public class RuntimeEntityDefinitionValidator(IOptions<RuntimeEntityOptions> options)
{
public void Validate(RuntimeEntityDefinition definition)
{
if (string.IsNullOrWhiteSpace(definition.Name))
throw new InvalidOperationException("Runtime entity definition name is required.");
if (definition.Fields.Count == 0)
throw new InvalidOperationException($"Runtime entity definition '{definition.Name}' must declare at least one field.");
var duplicateField = definition.Fields.GroupBy(x => x.Name, StringComparer.OrdinalIgnoreCase).FirstOrDefault(x => x.Count() > 1);
if (duplicateField is not null)
throw new InvalidOperationException($"Runtime entity definition '{definition.Name}' declares field '{duplicateField.Key}' more than once.");
var maxIndexedFields = Math.Min(options.Value.MaxIndexedFields, RuntimeEntityPersistenceSchemaProvider.IndexedFieldSlotCount);
if (definition.Indexes.Count > maxIndexedFields)
throw new InvalidOperationException($"Runtime entity definition '{definition.Name}' declares {definition.Indexes.Count} indexes, but only {maxIndexedFields} runtime index slots are available.");
var fields = definition.Fields.Select(x => x.Name).ToHashSet(StringComparer.OrdinalIgnoreCase);
foreach (var index in definition.Indexes)
{
if (!fields.Contains(index.FieldName))
throw new InvalidOperationException($"Runtime entity definition '{definition.Name}' index '{index.Name}' references unknown field '{index.FieldName}'.");
}
}
public void ValidateInstance(RuntimeEntityDefinition definition, RuntimeEntityInstance instance)
{
var dataKeys = instance.Data.Keys.ToHashSet(StringComparer.OrdinalIgnoreCase);
var missingField = definition.Fields.FirstOrDefault(x => x.IsRequired && !dataKeys.Contains(x.Name));
if (missingField is not null)
throw new InvalidOperationException($"Runtime entity instance '{instance.Id}' is missing required field '{missingField.Name}'.");
}
}
View on GitHub (pinned to fe9217bdfa)