{"record":{"id":"0ce086629cec7730","repo":"elsa-workflows/elsa-core","slug":"workflow-definition-with-id-workflowdefinitionid-not-found","errorCode":null,"errorMessage":"Workflow definition with ID '{workflowDefinitionId}' not found.","messagePattern":"Workflow definition with ID '(.+?)' not found\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/common/Elsa.Testing.Shared.Integration/RunWorkflowExtensions.cs","lineNumber":42,"sourceCode":"        /// Runs a workflow until its end, automatically resuming any bookmark it encounters.\n        /// </summary>\n        /// <param name=\"workflowDefinitionId\">The ID of the workflow definition.</param>\n        /// <param name=\"input\">An optional dictionary of input values.</param>\n        /// <param name=\"correlationId\">An optional correlation id of the workflow.</param>\n        /// <param name=\"versionOptions\">An optional set of options to specify the version of the workflow definition to retrieve.</param>\n        /// <param name=\"runWorkflowOptions\">Optional workflow execution options.</param>\n        /// <returns>The workflow state.</returns>\n        public async Task<WorkflowState> RunWorkflowUntilEndAsync(string workflowDefinitionId,\n            IDictionary<string, object>? input = null,\n            string? correlationId = null,\n            VersionOptions? versionOptions = null,\n            RunWorkflowOptions? runWorkflowOptions = null)\n        {\n            var workflowDefinitionService = services.GetRequiredService<IWorkflowDefinitionService>();\n            var workflowGraph = await workflowDefinitionService.FindWorkflowGraphAsync(workflowDefinitionId, versionOptions ?? VersionOptions.Published);\n\n            if (workflowGraph == null)\n                throw new InvalidOperationException($\"Workflow definition with ID '{workflowDefinitionId}' not found.\");\n\n            var workflowRuntime = services.GetRequiredService<IWorkflowRuntime>();\n            var workflowClient = await workflowRuntime.CreateClientAsync();\n            var response = await workflowClient.CreateAndRunInstanceAsync(new()\n            {\n                WorkflowDefinitionHandle = WorkflowDefinitionHandle.ByDefinitionVersionId(workflowGraph.Workflow.Identity.Id),\n                Input = input,\n                CorrelationId = correlationId,\n                Properties = runWorkflowOptions?.Properties\n            });\n\n            var bookmarkStore = services.GetRequiredService<IBookmarkStore>();\n\n            // Continue resuming the workflow for as long as there are bookmarks to resume and the workflow is not Finished.\n            while (response.Status != WorkflowStatus.Finished)\n            {\n                var bookmarks = (await bookmarkStore.FindManyAsync(new()\n                {","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/common/Elsa.Testing.Shared.Integration/RunWorkflowExtensions.cs#L24-L60","documentation":"RunWorkflowExtensions in Elsa.Testing.Shared resolves IWorkflowDefinitionService and calls FindWorkflowGraphAsync with the given definition ID and version options; when no workflow graph is found it throws InvalidOperationException. This means no workflow definition with that ID exists (or none matches the requested version state, e.g. Published when only Draft exists).","triggerScenarios":"Calling RunWorkflowAsync(services, \"some-id\") with an ID that was never registered/imported in the test's workflow definition store; the definition exists only as a Draft but the default VersionOptions.Published is requested; the definition was registered under a different definition ID than the one passed.","commonSituations":"Tests forget to add the workflow definition to the in-memory store before running; using the workflow's root ID when the store keys by a different identifier (or vice versa); a workflow imported without publishing, while the extension defaults to Published; renames of workflow definitions after tests were written.","solutions":["Register/import the workflow definition in the test setup before running (e.g. via the workflow definition import/publish API used elsewhere in the test suite).","Pass an explicit VersionOptions (e.g. VersionOptions.Latest or VersionOptions.SpecificVersion(n)) if the definition is not published.","Verify the workflowDefinitionId string matches the definition's ID (case and value) as stored.","Publish the definition if it exists only as a draft and the default Published lookup is intended."],"exampleFix":"// before\nawait services.RunWorkflowAsync(\"my-workflow\"); // not found: only a draft exists\n// after\nawait services.PopulateRegistriesAsync(); // or import + publish the definition first\nawait services.RunWorkflowAsync(\"my-workflow\", VersionOptions.Latest);","handlingStrategy":"validation","validationCode":"// check the definition exists (and matches version state) before running\nvar defService = services.GetRequiredService<IWorkflowDefinitionService>();\nvar graph = await defService.FindWorkflowGraphAsync(definitionId, VersionOptions.Published);\nif (graph is null)\n    throw new InvalidOperationException($\"Test setup error: definition '{definitionId}' missing or not published. Import/publish it first.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    await services.RunWorkflowAsync(definitionId);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"not found\"))\n{\n    Assert.Fail($\"Workflow definition '{definitionId}' is not registered/published in the test host: {ex.Message}\");\n}","preventionTips":["Import and publish workflow definitions in test setup (or use fixtures that do so) before running them.","Pass explicit VersionOptions matching how the definition was stored (Latest for drafts).","Reference definition IDs via shared constants instead of inline strings.","After renaming definitions, update all tests referencing the old ID."],"tags":["testing","workflow-definitions","not-found"],"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-15T23:17:13.987Z"}