Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Null Variables and Non-evaluating C#/JavaScript Expressions in Elsa Workflow Loaded from JSON #5960

Open
nitish-tt opened this issue Sep 13, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@nitish-tt
Copy link

I am running a WinForms application and loading a workflow from a JSON file exported from Elsa Studio. The workflow runs successfully, but I am unable to use any workflow variables; they always return null. Additionally, any C# or JavaScript expressions I attempt to use do not evaluate, causing a runtime error.

The call stack reveals a NullReferenceException as shown below:

`Elsa.Workflows.Middleware.Activities.ExceptionHandlingMiddleware: Warning: An exception was caught from a downstream middleware component

System.NullReferenceException: Object reference not set to an instance of an object.
at Submission#4.<>d__0.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync(...)
at Elsa.CSharp.Services.CSharpEvaluator.EvaluateAsync(...)
at Elsa.CSharp.Expressions.CSharpExpressionHandler.EvaluateAsync(...)
at Elsa.Extensions.ActivityExecutionContextExtensions.EvaluateInputPropertiesAsync(...)
at Elsa.Workflows.Middleware.Activities.DefaultActivityInvokerMiddleware.InvokeAsync(...)
`

Steps to Reproduce

  1. Load a workflow exported from Elsa Studio in a WinForms application.
  2. Attempt to use workflow variables or evaluate C#/JavaScript expressions within the workflow.
  3. Observe that the workflow completes but variables are null and expressions do not evaluate.

Expected Behavior
Variables should be accessible and return valid values, and C# or JavaScript expressions should evaluate correctly during the workflow execution.

Actual Behavior
Variables always return null and expressions are not evaluated, leading to a NullReferenceException in the workflow execution.

Log Output
Logs show the following warning message related to the null reference error:

`Elsa.Workflows.Middleware.Activities.ExceptionHandlingMiddleware: Warning: An exception was caught from a downstream middleware component

System.NullReferenceException: Object reference not set to an instance of an object.
`

Additional Context
This issue only occurs when running the workflow from a JSON file exported from Elsa Studio in Winfrom Application. The same expressions and variable manipulations work correctly when run on elsa server.

https://v3.elsaworkflows.io/docs/guides/loading-workflows-from-json
this is Code i m using in my Winfrom Aplication.

@nitish-tt nitish-tt added the bug Something isn't working label Sep 13, 2024
@nitish-tt
Copy link
Author

`using Elsa.Workflows.Attributes;
using Elsa.Workflows.Models;
using Elsa.Workflows;
using System.Text.Json;
using Elsa.Extensions;

namespace ElsaServer.StorageActivity
{
[Activity("StorageActivity",
Category = "Data Storage",
Description = "Loads a serialized workflow variable's data from a file."
)]
public class GetVariableValueFromFile : CodeActivity
{
public Input VariableName { get; set; } = default!;

    public Input<string> FilePath { get; set; } = default!;

    protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
    {
        var filePath = context.Get(FilePath);
        var variableName = context.Get(VariableName);
        var variable = context.WorkflowExecutionContext.Variables.FirstOrDefault(f => f.Name == variableName);
        // this geting null
    }
}

}
`

@nitish-tt
Copy link
Author

Forgot to mention that I am running Elsa 3.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant