{"record":{"id":"741a639be0ccf171","repo":"elsa-workflows/elsa-core","slug":"runtime-entity-definition-definition-name-must-declare-at","errorCode":null,"errorMessage":"Runtime entity definition '{definition.Name}' must declare at least one field.","messagePattern":"Runtime entity definition '(.+?)' must declare at least one field\\.","errorType":"validation","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Persistence.VNext.Runtime/Services/RuntimeEntityDefinitionValidator.cs","lineNumber":14,"sourceCode":"using Elsa.Persistence.VNext.Runtime.Models;\nusing Microsoft.Extensions.Options;\n\nnamespace Elsa.Persistence.VNext.Runtime.Services;\n\npublic class RuntimeEntityDefinitionValidator(IOptions<RuntimeEntityOptions> options)\n{\n    public void Validate(RuntimeEntityDefinition definition)\n    {\n        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)","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Persistence.VNext.Runtime/Services/RuntimeEntityDefinitionValidator.cs#L1-L32","documentation":"A runtime entity definition must declare at least one field; a fieldless definition has no storage representation. Validate throws InvalidOperationException for definitions with an empty Fields collection.","triggerScenarios":"Calling Validate with a RuntimeEntityDefinition whose Fields list has zero entries — e.g. built without adding fields or with all fields conditionally skipped.","commonSituations":"Config-driven definitions where the fields section is empty or misnamed so nothing binds; conditional registration code that adds no fields for a given environment; copy-pasted definition skeleton not yet filled in.","solutions":["Add at least one Field to the definition before validating.","If fields are configured externally, fix the config source so the field list binds and is non-empty.","Guard conditional field-adding logic so an all-false branch is treated as a configuration error at construction time."],"exampleFix":"// before\nvar def = new RuntimeEntityDefinition { Name = \"Events\" };\nvalidator.Validate(def); // Fields is empty\n// after\nvar def = new RuntimeEntityDefinition { Name = \"Events\" };\ndef.Fields.Add(new RuntimeEntityField { Name = \"OccurredAt\", IsRequired = true });\nvalidator.Validate(def);","handlingStrategy":"validation","validationCode":"if (definition.Fields.Count == 0) throw new InvalidOperationException($\"Definition '{definition.Name}' has no fields.\");","typeGuard":null,"tryCatchPattern":"try { validator.Validate(definition); }\ncatch (InvalidOperationException ex) { logger.LogError(ex, \"Definition {Name} invalid\", definition.Name); throw; }","preventionTips":["Require at least one field in the builder's WithFields call.","Fail at startup registration when a configured field list binds empty.","Add tests covering each configured definition."],"tags":["validation","runtime-entities","schema"],"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"}