{"record":{"id":"b8362ca90da0c3ad","repo":"elsa-workflows/elsa-core","slug":"runtime-entity-definition-name-was-not-found","errorCode":null,"errorMessage":"Runtime entity definition '{name}' was not found.","messagePattern":"Runtime entity definition '(.+?)' was not found\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":404,"severity":"error","filePath":"src/modules/Elsa.Persistence.VNext.Runtime/Services/RuntimeEntityManager.cs","lineNumber":42,"sourceCode":"        var now = DateTimeOffset.UtcNow;\n        definition.CreatedAt = existing?.Definition.CreatedAt ?? definition.CreatedAt;\n        definition.UpdatedAt = now;\n\n        await SaveDefinitionAsync(definition, existing?.Document.Version ?? 0, cancellationToken);\n        await AppendAuditAsync(\"RuntimeEntityDefinition\", definition.Name, \"DraftSaved\", $\"Draft version {definition.Version} saved.\", cancellationToken);\n        return definition;\n    }\n\n    public async Task<RuntimeEntityDefinition?> GetDefinitionAsync(string name, CancellationToken cancellationToken = default)\n    {\n        var result = await LoadDefinitionDocumentAsync(name, cancellationToken);\n        return result?.Definition;\n    }\n\n    public async Task<RuntimeEntityDefinition> PublishAsync(string name, CancellationToken cancellationToken = default)\n    {\n        var existing = await LoadDefinitionDocumentAsync(name, cancellationToken)\n            ?? throw new InvalidOperationException($\"Runtime entity definition '{name}' was not found.\");\n\n        existing.Definition.Status = RuntimeEntityDefinitionStatus.Published;\n        existing.Definition.UpdatedAt = DateTimeOffset.UtcNow;\n        validator.Validate(existing.Definition);\n\n        await SaveDefinitionAsync(existing.Definition, existing.Document.Version, cancellationToken);\n        await AppendAuditAsync(\"RuntimeEntityDefinition\", existing.Definition.Name, \"Published\", $\"Version {existing.Definition.Version} published.\", cancellationToken);\n        return existing.Definition;\n    }\n\n    public async Task<RuntimeEntityDefinition> RetireAsync(string name, CancellationToken cancellationToken = default)\n    {\n        var existing = await LoadDefinitionDocumentAsync(name, cancellationToken)\n            ?? throw new InvalidOperationException($\"Runtime entity definition '{name}' was not found.\");\n\n        existing.Definition.Status = RuntimeEntityDefinitionStatus.Retired;\n        existing.Definition.UpdatedAt = DateTimeOffset.UtcNow;\n","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Persistence.VNext.Runtime/Services/RuntimeEntityManager.cs#L24-L60","documentation":"PublishAsync loads a previously saved runtime entity definition document by (normalized) name and marks it Published. When no stored definition document exists under that name, the manager throws InvalidOperationException with the requested name. Publishing requires a prior SaveDraftAsync; it is not a create operation.","triggerScenarios":"Calling PublishAsync(name) where name was never saved via SaveDraftAsync, was saved under a different casing/spelling (names are normalized to trimmed lowercase), or the underlying document store lost the record.","commonSituations":"Typo or inconsistent casing in the definition name; deploying to a fresh database without migrating definitions; calling publish in a CI pipeline before the draft-save step ran; definition was deleted by another process.","solutions":["Save a draft first with SaveDraftAsync(new RuntimeEntityDefinition { Name = name, ... }) before calling PublishAsync.","Verify the exact name via GetDefinitionAsync(name); names are trimmed and lowercased by NormalizeName, so use the normalized form.","Check that the configured IDocumentStore points to the database/environment that actually contains the definition."],"exampleFix":"// before\nawait manager.PublishAsync(\"Orders\");\n// after\nif (await manager.GetDefinitionAsync(\"orders\") is null)\n    await manager.SaveDraftAsync(new RuntimeEntityDefinition { Name = \"orders\", Version = 1 });\nawait manager.PublishAsync(\"orders\");","handlingStrategy":"validation","validationCode":"if (await manager.GetDefinitionAsync(name) is null)\n    throw new InvalidOperationException($\"Definition '{name}' must be saved before publishing.\");","typeGuard":null,"tryCatchPattern":"try { await manager.PublishAsync(name); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"was not found\")) { /* provision or report */ }","preventionTips":["Always pair SaveDraftAsync with PublishAsync in provisioning code.","Store definition names as normalized lowercase constants.","Verify GetDefinitionAsync returns non-null in smoke tests after deployment."],"tags":["persistence","entity-not-found","csharp"],"backgroundTag":"entity-not-found","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"}