{"record":{"id":"29fdebae1790e398","repo":"elsa-workflows/elsa-core","slug":"workflowexecutioncontext-not-found-this-value-exists-only-on","errorCode":null,"errorMessage":"WorkflowExecutionContext not found. This value exists only on activity execution contexts.","messagePattern":"WorkflowExecutionContext not found\\. This value exists only on activity execution contexts\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Workflows.Core/Extensions/ExpressionExecutionContextExtensions.cs","lineNumber":82,"sourceCode":"            [InputKey] = input\n        };\n\n    /// <param name=\"context\">The context to start searching from.</param>\n    extension(ExpressionExecutionContext context)\n    {\n        /// <summary>\n        /// Returns the <see cref=\"Workflow\"/> of the specified <see cref=\"ExpressionExecutionContext\"/>\n        /// </summary>\n        public bool TryGetWorkflowExecutionContext(out WorkflowExecutionContext workflowExecutionContext) => context.TransientProperties.TryGetValue(WorkflowExecutionContextKey, out workflowExecutionContext!);\n\n        /// <summary>\n        /// Returns the <see cref=\"WorkflowExecutionContext\"/> of the specified <see cref=\"ExpressionExecutionContext\"/>\n        /// </summary>\n        public WorkflowExecutionContext GetWorkflowExecutionContext()\n        {\n            return context.TransientProperties.TryGetValue(WorkflowExecutionContextKey, out var value)\n                ? (WorkflowExecutionContext)value\n                : throw new InvalidOperationException(\"WorkflowExecutionContext not found. This value exists only on activity execution contexts.\");\n        }\n\n        /// <summary>\n        /// Returns the <see cref=\"ActivityExecutionContext\"/> of the specified <see cref=\"ExpressionExecutionContext\"/>\n        /// </summary>\n        public ActivityExecutionContext GetActivityExecutionContext()\n        {\n            return context.TransientProperties.TryGetValue(ActivityExecutionContextKey, out var value)\n                ? (ActivityExecutionContext)value\n                : throw new InvalidOperationException(\"ActivityExecutionContext not found. This value exists only on activity execution contexts.\");\n        }\n\n        /// <summary>\n        /// Returns the <see cref=\"ActivityExecutionContext\"/> of the specified <see cref=\"ExpressionExecutionContext\"/>\n        /// </summary>\n        public bool TryGetActivityExecutionContext(out ActivityExecutionContext activityExecutionContext) => context.TransientProperties.TryGetValue(ActivityExecutionContextKey, out activityExecutionContext!);\n\n        /// <summary>","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Workflows.Core/Extensions/ExpressionExecutionContextExtensions.cs#L64-L100","documentation":"An InvalidOperationException thrown by GetWorkflowExecutionContext when the ExpressionExecutionContext's TransientProperties dictionary does not contain the WorkflowExecutionContext key. WorkflowExecutionContext is only attached to transient properties when an expression is evaluated within an activity execution; standalone evaluations lack it.","triggerScenarios":"Calling GetWorkflowExecutionContext() on an ExpressionExecutionContext created outside activity execution - e.g., evaluating an expression at design time, in a workflow-level (not activity-level) context, or via a custom evaluator that did not populate TransientProperties.","commonSituations":"Custom expression syntax/plugins that evaluate expressions without the normal activity pipeline; designer-time evaluation/preview; background jobs evaluating stored expressions without a running workflow; unit tests constructing bare ExpressionExecutionContexts.","solutions":["Only call this inside code that runs during activity execution, where TransientProperties is populated.","Use TryGetValue on context.TransientProperties with the WorkflowExecutionContextKey to test presence first.","Pass the WorkflowExecutionContext explicitly to your evaluation code instead of pulling it from the expression context.","In tests, populate TransientProperties[WorkflowExecutionContextKey] with a real or stubbed context."],"exampleFix":"// before\nvar workflowExecutionContext = context.GetWorkflowExecutionContext(); // throws outside activity execution\n\n// after\nif (context.TransientProperties.TryGetValue(WorkflowExecutionContextKey, out var value) && value is WorkflowExecutionContext wfCtx)\n{\n    // use wfCtx\n}","handlingStrategy":"type-guard","validationCode":"var hasWorkflowContext = expressionContext.TransientProperties.ContainsKey(WorkflowExecutionContextKey);","typeGuard":"bool TryGetWorkflowExecutionContext(ExpressionExecutionContext ctx, out WorkflowExecutionContext? wfCtx)\n    => ctx.TransientProperties.TryGetValue(WorkflowExecutionContextKey, out var v) && (wfCtx = v as WorkflowExecutionContext) is not null;","tryCatchPattern":"catch (InvalidOperationException ex) when (ex.Message.StartsWith(\"WorkflowExecutionContext not found\"))\n{\n    // fall back to explicit context passing\n}","preventionTips":["Only evaluate expressions inside activity execution.","Pass WorkflowExecutionContext explicitly in custom evaluators.","Use TryGetValue patterns instead of throwing getters in library extensions."],"tags":["expression","workflow","csharp"],"backgroundTag":"missing-dependency","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"}