{"record":{"id":"546d15c9e6c4fbb8","repo":"elsa-workflows/elsa-core","slug":"could-not-find-workflow-definition-with-id","errorCode":null,"errorMessage":"Could not find workflow definition with ID {WorkflowDefinitionId}.","messagePattern":"Could not find workflow definition with ID (.+?)\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Workflows.Management/Activities/WorkflowDefinitionActivity/WorkflowDefinitionActivity.cs","lineNumber":58,"sourceCode":"    /// </summary>\n    public string? LatestAvailablePublishedVersionId { get; set; }\n\n    async ValueTask IInitializable.InitializeAsync(InitializationContext context)\n    {\n        // This is not just for efficiency but also a necessity to avoid potential race conditions.\n        // Such conditions can occur when multiple threads are simultaneously creating consuming workflows,\n        // especially when cached workflows are being updated during the graph construction process.\n        if (IsInitialized)\n            return;\n\n        var serviceProvider = context.ServiceProvider;\n        var cancellationToken = context.CancellationToken;\n\n        // Find the workflow definition and not the graph; the graph must be computed at runtime, since NodeIds will vary across graphs.\n        var workflowDefinition = await GetWorkflowDefinitionAsync(serviceProvider, cancellationToken);\n\n        if (workflowDefinition == null)\n            throw new Exception($\"Could not find workflow definition with ID {WorkflowDefinitionId}.\");\n\n        var activityDescriptor = await FindActivityDescriptorAsync(serviceProvider);\n\n        if (activityDescriptor == null)\n        {\n            var logger = serviceProvider.GetRequiredService<ILogger<WorkflowDefinitionActivity>>();\n            logger.LogWarning(\"Could not find activity descriptor for activity type {ActivityType}\", Type);\n        }\n        else\n        {\n            // Declare input and output variables.\n            DeclareInputAsVariables(activityDescriptor, (_, variable) => Variables.Declare(variable));\n            DeclareOutputAsVariables(activityDescriptor, (_, variable) => Variables.Declare(variable));\n        }\n\n        var workflowDefinitionService = serviceProvider.GetRequiredService<IWorkflowDefinitionService>();\n        var workflowGraph = await workflowDefinitionService.MaterializeWorkflowAsync(workflowDefinition, cancellationToken);\n","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Workflows.Management/Activities/WorkflowDefinitionActivity/WorkflowDefinitionActivity.cs#L40-L76","documentation":"Thrown during WorkflowDefinitionActivity.InitializeAsync when the workflow definition referenced by WorkflowDefinitionId cannot be loaded from the definition store. The activity wraps another workflow definition, so a missing definition means the graph cannot be resolved at initialization time.","triggerScenarios":"WorkflowDefinitionId points to a definition that was deleted, is a draft/unpublished version not visible to the runtime, lives in a different tenant, or the IWorkflowDefinitionProvider/store is misconfigured (e.g., wrong connection string, no definitions deployed).","commonSituations":"Definitions removed during cleanup while referring workflows remain, environment migrations where definitions were not deployed to the target database, multi-tenant setups where the definition exists only in another tenant, and referencing definitions by ID copied from a dev environment into production.","solutions":["Verify WorkflowDefinitionId matches an existing, published definition in the runtime's definition store (check the dashboard/API).","Publish the target workflow definition if it is still in draft.","Deploy/migrate the definitions to the current environment's database or fix the persistence connection configuration.","Check tenancy: ensure the definition exists in the tenant the workflow executes under.","Guard against deleted definitions by removing or updating referencing WorkflowDefinitionActivity instances when deleting a definition."],"exampleFix":"// before\nactivity.WorkflowDefinitionId = \"9a1f...\"; // deleted definition\n\n// after: resolve the ID from the management API at build time\nvar definition = await workflowDefinitionManager.FindByDefinitionIdAsync(\"my-flow\", VersionOptions.Published);\nactivity.WorkflowDefinitionId = definition!.DefinitionId;","handlingStrategy":"try-catch","validationCode":"var exists = (await workflowDefinitionManager.FindByDefinitionIdAsync(id, VersionOptions.Published)) != null;\nif (!exists) throw new InvalidOperationException($\"Referenced workflow definition '{id}' is not published in this environment/tenant.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    await workflowDefinitionActivity.ExecuteAsync(context);\n}\ncatch (Exception ex) when (ex.Message.StartsWith(\"Could not find workflow definition with ID\"))\n{\n    logger.LogError(ex, \"Referenced definition {Id} missing; ensure it is published and deployed\", workflowDefinitionId);\n    // compensate: notify ops or route to a fallback path\n}","preventionTips":["Verify the referenced definition exists and is published in every target environment before deploying referring workflows.","Include definition deployment in your migration/release checklist.","Check tenant configuration when running multi-tenant.","Avoid hardcoding IDs from other environments; resolve published definitions by name at deploy time."],"tags":["workflow-definition","not-found","persistence"],"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-16T04:17:20.429Z"}