elsa-workflows / elsa-core

A .NET workflows library
https://v3.elsaworkflows.io/
MIT License
5.88k stars 1.06k forks source link

CSharp expression - Access last activity output result #5260

Open rmanjusha opened 3 weeks ago

rmanjusha commented 3 weeks ago

Hi ,

I am trying to access last activity output result inside 'If' branching condition using csharp expression to decide on next workflow step as - ((MyType)Output.LastResult).PropertyName , but getting below error.

error CS0246: The type or namespace name 'MyType' could not be found (are you missing a using directive or an assembly reference?)

How can I add assembly reference ? Please advise.

glime-ai[bot] commented 3 weeks ago

To resolve the error CS0246 and correctly cast the Output.LastResult to your custom type MyType, you need to ensure that the assembly containing MyType is referenced by the project where you are using the Elsa workflow. If MyType is defined within the same project, you should not encounter this issue as long as the namespace is correct.

However, if MyType is defined in a different assembly, you need to add a reference to that assembly in your project. You can do this by adding a project reference or a package reference if the assembly is packaged as a NuGet package.

Here are the steps to add a reference to an assembly:

  1. If the assembly is available as a NuGet package:

    • Use the NuGet Package Manager to install the package.
    • Use the Package Manager Console with the command: Install-Package YourPackageName.
  2. If the assembly is not packaged as a NuGet package:

    • Right-click on the project in the Solution Explorer.
    • Click on "Add" and then "Reference...".
    • In the Reference Manager, go to the "Browse" tab and locate the assembly file (DLL) you want to reference.
    • Select the assembly and click "Add".

After adding the reference, ensure that the correct using directive is included at the top of your C# file where you are trying to use MyType.

If you are trying to use MyType within Elsa's C# expression evaluator and the type is not recognized, it could be due to limitations in the scripting environment. Elsa uses Roslyn for C# expression evaluation, and by default, it references only a limited set of assemblies. You may need to configure Elsa to include additional assemblies for the scripting environment.

Unfortunately, as of my knowledge cutoff date in early 2023, there is no direct way to add assembly references specifically for the C# expression evaluator within Elsa workflows. If you are facing this issue within the Elsa scripting environment, you may need to reach out to the Elsa community or maintainers for guidance on how to extend the scripting capabilities to include custom types.

If you provide more context or specify where you are trying to add the assembly reference (e.g., within a custom activity, within a script task, etc.), I could give you more targeted advice.

This comment was generated by Glime.

rmanjusha commented 3 weeks ago

I have required references in my project .

I am looking for a way to include additional assemblies to scripting environment.

rmanjusha commented 3 weeks ago

@sfmskywalker Please advise. I am using result of a custom activity with result as object inside if condition.

Tried passing boolean output result as well , but fails with error :

The memory block 'Elsa.Expressions.Models.MemoryBlockReference' does not exist.

image