diff --git a/src/UiPath.Workflow.Runtime/Expressions/CompiledExpressionInvoker.cs b/src/UiPath.Workflow.Runtime/Expressions/CompiledExpressionInvoker.cs index ee2d6166..dd5c90c3 100644 --- a/src/UiPath.Workflow.Runtime/Expressions/CompiledExpressionInvoker.cs +++ b/src/UiPath.Workflow.Runtime/Expressions/CompiledExpressionInvoker.cs @@ -22,6 +22,7 @@ public class CompiledExpressionInvoker private readonly IList _locationReferences; private CodeActivityMetadata _metadata; private CodeActivityPublicEnvironmentAccessor _accessor; + private bool _locationsInitialized; public CompiledExpressionInvoker(ITextExpression expression, bool isReference, CodeActivityMetadata metadata) { @@ -40,7 +41,10 @@ public CompiledExpressionInvoker(ITextExpression expression, bool isReference, C _metadataRoot = metadata.Environment.Root; - ProcessLocationReferences(); + if (!metadata.Environment.IsValidating) + { + ProcessLocationReferences(); + } } public object InvokeExpression(ActivityContext activityContext) @@ -50,6 +54,11 @@ public object InvokeExpression(ActivityContext activityContext) throw FxTrace.Exception.ArgumentNull(nameof(activityContext)); } + if (!_locationsInitialized) + { + ProcessLocationReferences(); + } + if (_compiledRoot == null || _expressionId < 0) { if (!TryGetCompiledExpressionRoot(_expressionActivity, _metadataRoot, out _compiledRoot) || @@ -154,6 +163,11 @@ internal static bool TryGetCompiledExpressionRoot(Activity target, bool forImple internal Expression GetExpressionTree() { + if (!_locationsInitialized) + { + ProcessLocationReferences(); + } + if (_compiledRoot == null || _expressionId < 0) { if (!TryGetCompiledExpressionRootAtDesignTime(_expressionActivity, _metadataRoot, out _compiledRoot, out _expressionId)) @@ -198,6 +212,8 @@ private bool CanExecuteExpression(ICompiledExpressionRoot compiledExpressionRoot private void ProcessLocationReferences() { + _locationsInitialized = true; + Stack environments = new(); // // Build list of location by enumerating environments