{"record":{"id":"0875dcca7e45b76c","repo":"elsa-workflows/elsa-core","slug":"runtime-entity-definition-definition-name-index-index-name","errorCode":null,"errorMessage":"Runtime entity definition '{definition.Name}' index '{index.Name}' references unknown field '{index.FieldName}'.","messagePattern":"Runtime entity definition '(.+?)' index '(.+?)' references unknown field '(.+?)'\\.","errorType":"validation","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Persistence.VNext.Runtime/Services/RuntimeEntityDefinitionValidator.cs","lineNumber":28,"sourceCode":"        if (string.IsNullOrWhiteSpace(definition.Name))\n            throw new InvalidOperationException(\"Runtime entity definition name is required.\");\n\n        if (definition.Fields.Count == 0)\n            throw new InvalidOperationException($\"Runtime entity definition '{definition.Name}' must declare at least one field.\");\n\n        var duplicateField = definition.Fields.GroupBy(x => x.Name, StringComparer.OrdinalIgnoreCase).FirstOrDefault(x => x.Count() > 1);\n        if (duplicateField is not null)\n            throw new InvalidOperationException($\"Runtime entity definition '{definition.Name}' declares field '{duplicateField.Key}' more than once.\");\n\n        var maxIndexedFields = Math.Min(options.Value.MaxIndexedFields, RuntimeEntityPersistenceSchemaProvider.IndexedFieldSlotCount);\n        if (definition.Indexes.Count > maxIndexedFields)\n            throw new InvalidOperationException($\"Runtime entity definition '{definition.Name}' declares {definition.Indexes.Count} indexes, but only {maxIndexedFields} runtime index slots are available.\");\n\n        var fields = definition.Fields.Select(x => x.Name).ToHashSet(StringComparer.OrdinalIgnoreCase);\n        foreach (var index in definition.Indexes)\n        {\n            if (!fields.Contains(index.FieldName))\n                throw new InvalidOperationException($\"Runtime entity definition '{definition.Name}' index '{index.Name}' references unknown field '{index.FieldName}'.\");\n        }\n    }\n\n    public void ValidateInstance(RuntimeEntityDefinition definition, RuntimeEntityInstance instance)\n    {\n        var dataKeys = instance.Data.Keys.ToHashSet(StringComparer.OrdinalIgnoreCase);\n        var missingField = definition.Fields.FirstOrDefault(x => x.IsRequired && !dataKeys.Contains(x.Name));\n        if (missingField is not null)\n            throw new InvalidOperationException($\"Runtime entity instance '{instance.Id}' is missing required field '{missingField.Name}'.\");\n    }\n}\n","sourceCodeStart":10,"sourceCodeEnd":40,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Persistence.VNext.Runtime/Services/RuntimeEntityDefinitionValidator.cs#L10-L40","documentation":"Every index on a runtime entity definition must reference a field declared in that same definition (name match is case-insensitive). Validate throws when an index points at a field that does not exist, since no storage slot exists for it.","triggerScenarios":"Calling Validate where an index's FieldName is not among the definition's field names, ignoring case — usually a typo or a field removed while its index remained.","commonSituations":"Renaming a field without updating indexes; typo in a config-driven index definition; copying an index block from another entity definition.","solutions":["Fix the index's FieldName to exactly match a declared field's name (case-insensitive but otherwise identical).","If the field was intentionally removed, delete the corresponding index too.","Add the missing field to the definition if the index is actually required."],"exampleFix":"// before\ndef.Fields.Add(new RuntimeEntityField { Name = \"CorrelationId\" });\ndef.Indexes.Add(new RuntimeEntityIndex { Name = \"IX_Correlation\", FieldName = \"CorrelationID\" }); // mismatch\n// after\ndef.Indexes.Add(new RuntimeEntityIndex { Name = \"IX_Correlation\", FieldName = \"CorrelationId\" });","handlingStrategy":"validation","validationCode":"var fieldNames = definition.Fields.Select(f => f.Name).ToHashSet(StringComparer.OrdinalIgnoreCase);\nvar bad = definition.Indexes.Where(i => !fieldNames.Contains(i.FieldName)).ToList();\nif (bad.Count > 0) throw new InvalidOperationException($\"Indexes referencing unknown fields: {string.Join(\", \", bad.Select(b => b.FieldName))}\");","typeGuard":null,"tryCatchPattern":"try { validator.Validate(definition); }\ncatch (InvalidOperationException ex) { logger.LogError(ex, \"Index field mismatch in {Name}\", definition.Name); throw; }","preventionTips":["Reference fields via shared constants used in both the field and index declarations.","Rename fields and their indexes together in the same change.","Validate definitions in unit tests for every entity."],"tags":["validation","runtime-entities","index"],"backgroundTag":"schema-validation-failed","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}