elsa-workflows / elsa-core

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

Elsa 3.1 - csharp script - extend the scripting capabilities to include custom types #5265

Open rmanjusha opened 3 weeks ago

rmanjusha commented 3 weeks ago

Feature Request

Elsa 3.1 - csharp script - extend the scripting capabilities to include custom types

Problem Overview

CSharp expression evaluator fails to execute - ((MyType)Output.LastResult).PropertyName with error error CS0246: The type or namespace name 'MyType' could not be found (are you missing a using directive or an assembly reference?)

Proposed Solution

Capability to add custom namespaces and assemblies to CSharpOptions

glime-ai[bot] commented 3 weeks ago

To address the issue of the C# expression evaluator failing to execute due to the inability to find custom types like MyType, you can extend the scripting capabilities to include custom types by registering the necessary assemblies with the C# expression evaluator. Elsa uses Roslyn to implement the C# expression evaluator, and you can configure it to include additional assemblies and namespaces that contain your custom types.

Here's a general approach to how you might extend the scripting capabilities:

  1. Identify the assemblies that contain the custom types you want to use in your expressions.
  2. Register these assemblies with the C# expression evaluator so that they are available during script execution.

Unfortunately, as of my knowledge cutoff date in early 2023, there is no direct documentation on how to do this specifically for Elsa Workflows. However, since Elsa uses Roslyn, you might be able to configure the ScriptOptions used by Roslyn to add references to your custom assemblies.

You may need to look into the Elsa source code or contact the Elsa community for guidance on how to properly configure the ScriptOptions for Elsa's C# expression evaluator. Additionally, keep an eye on the Elsa GitHub issues and discussions, as this is a feature that other users have expressed interest in, and there may be updates or solutions provided by the Elsa team or community.

If you are experiencing this issue with a specific version of Elsa, please provide the version number, and I can give you more targeted advice.

This comment was generated by Glime.