{"record":{"id":"69ebcd1caed6a046","repo":"elsa-workflows/elsa-core","slug":"runtime-entity-definition-name-is-required","errorCode":null,"errorMessage":"Runtime entity definition name is required.","messagePattern":"Runtime entity definition name is required\\.","errorType":"validation","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Persistence.VNext.Runtime/Services/RuntimeEntityDefinitionValidator.cs","lineNumber":11,"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        }","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Persistence.VNext.Runtime/Services/RuntimeEntityDefinitionValidator.cs#L1-L29","documentation":"RuntimeEntityDefinitionValidator.Validate enforces that every runtime entity definition has a non-empty Name. The name is used to resolve the entity's persistence schema, so an unnamed definition cannot be validated further or mapped to storage.","triggerScenarios":"Calling Validate with a RuntimeEntityDefinition whose Name is null, empty, or whitespace — typically a definition constructed programmatically or via options where the name was never set.","commonSituations":"Missing configuration entry that feeds the definition name; a builder used without calling a required WithName/Name setter; diagnostics registering definitions before configuration binding.","solutions":["Set definition.Name to a stable, non-empty identifier before calling Validate.","If the name comes from options/configuration, verify the config section is bound and the key exists.","Check the construction/builder path to ensure the name is a required parameter rather than an optional property."],"exampleFix":"// before\nvar def = new RuntimeEntityDefinition { Fields = { ... } };\nvalidator.Validate(def);\n// after\nvar def = new RuntimeEntityDefinition { Name = \"AuditEvents\", Fields = { ... } };\nvalidator.Validate(def);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(definition.Name)) throw new InvalidOperationException(\"Runtime entity definition must have a Name.\");","typeGuard":null,"tryCatchPattern":"try { validator.Validate(definition); }\ncatch (InvalidOperationException ex) { logger.LogError(ex, \"Invalid runtime entity definition\"); throw; }","preventionTips":["Make Name a required constructor/builder argument.","Validate definitions at startup, before first use.","Bind names from configuration with fail-fast checks."],"tags":["validation","runtime-entities","configuration"],"backgroundTag":"empty-required-field","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}