diff --git a/src/core/Elsa.Abstractions/Services/Models/ActivityExecutionContext.cs b/src/core/Elsa.Abstractions/Services/Models/ActivityExecutionContext.cs index 2ab117fbf..4cade4819 100644 --- a/src/core/Elsa.Abstractions/Services/Models/ActivityExecutionContext.cs +++ b/src/core/Elsa.Abstractions/Services/Models/ActivityExecutionContext.cs @@ -107,7 +107,7 @@ namespace Elsa.Services.Models set => WorkflowExecutionContext.WorkflowInstance.ActivityOutput.SetItem(ActivityBlueprint.Id, value); } - public ActivityScope CurrentScope => WorkflowExecutionContext.CurrentScope; + public ActivityScope? CurrentScope => WorkflowExecutionContext.CurrentScope; public ActivityScope GetScope(string activityId) => WorkflowExecutionContext.GetScope(activityId); public ActivityScope GetNamedScope(string activityName) => WorkflowExecutionContext.GetNamedScope(activityName); diff --git a/src/core/Elsa.Abstractions/Services/Models/WorkflowExecutionContext.cs b/src/core/Elsa.Abstractions/Services/Models/WorkflowExecutionContext.cs index 6794c2071..dae078d7c 100644 --- a/src/core/Elsa.Abstractions/Services/Models/WorkflowExecutionContext.cs +++ b/src/core/Elsa.Abstractions/Services/Models/WorkflowExecutionContext.cs @@ -150,7 +150,7 @@ namespace Elsa.Services.Models public void PurgeVariables() => WorkflowInstance.Variables.RemoveAll(); - public ActivityScope CurrentScope => WorkflowInstance.Scopes.Peek(); + public ActivityScope? CurrentScope => WorkflowInstance.Scopes.Any() ? WorkflowInstance.Scopes.Peek() : default; public ActivityScope GetScope(string activityId) => WorkflowInstance.Scopes.First(x => x.ActivityId == activityId); public ActivityScope GetNamedScope(string activityName) diff --git a/src/core/Elsa.Core/Activities/ControlFlow/For/ForScope.cs b/src/core/Elsa.Core/Activities/ControlFlow/For/ForScope.cs index 901906f94..68adc8ed2 100644 --- a/src/core/Elsa.Core/Activities/ControlFlow/For/ForScope.cs +++ b/src/core/Elsa.Core/Activities/ControlFlow/For/ForScope.cs @@ -12,7 +12,7 @@ namespace Elsa.Activities.ControlFlow public static class ForActivityScopeExtensions { - public static ForScope ForScope(this ActivityExecutionContext context) => new(context.CurrentScope); + public static ForScope ForScope(this ActivityExecutionContext context) => new(context.CurrentScope!); public static ForScope ForScope(this ActivityExecutionContext context, string activityId) => new(context.GetScope(activityId)); public static ForScope ForNamedScope(this ActivityExecutionContext context, string activityId) => new(context.GetNamedScope(activityId)); } diff --git a/src/core/Elsa.Core/Activities/ControlFlow/ForEach/ForEachScope.cs b/src/core/Elsa.Core/Activities/ControlFlow/ForEach/ForEachScope.cs index a38e74821..6d9c23e45 100644 --- a/src/core/Elsa.Core/Activities/ControlFlow/ForEach/ForEachScope.cs +++ b/src/core/Elsa.Core/Activities/ControlFlow/ForEach/ForEachScope.cs @@ -17,10 +17,10 @@ namespace Elsa.Activities.ControlFlow public static class ForEachActivityScopeExtensions { - public static ForEachScope ForEachScope(this ActivityExecutionContext context) => new(context.CurrentScope); + public static ForEachScope ForEachScope(this ActivityExecutionContext context) => new(context.CurrentScope!); public static ForEachScope ForEachScope(this ActivityExecutionContext context, string activityId) => new(context.GetScope(activityId)); public static ForEachScope ForEachNamedScope(this ActivityExecutionContext context, string activityName) => new(context.GetNamedScope(activityName)); - public static ForEachScope ForEachScope(this ActivityExecutionContext context) => new(context.CurrentScope); + public static ForEachScope ForEachScope(this ActivityExecutionContext context) => new(context.CurrentScope!); public static ForEachScope ForEachScope(this ActivityExecutionContext context, string activityId) => new(context.GetScope(activityId)); public static ForEachScope ForEachNamedScope(this ActivityExecutionContext context, string activityName) => new(context.GetNamedScope(activityName));