Fix System.Dynamic registration for C# variable accessors#7415
Conversation
Greptile SummaryThis PR fixes a missing Confidence Score: 5/5Safe to merge — the fix is minimal, well-guarded, and the only remaining finding is a P2 test coverage gap. The implementation correctly mirrors the existing No files require special attention.
|
| Filename | Overview |
|---|---|
| src/modules/Elsa.Expressions.CSharp/Handlers/GenerateWorkflowVariableAccessors.cs | Adds System.Dynamic namespace import and ExpandoObject assembly reference when an ExpandoObject-typed variable is in scope and wrappers are enabled — correctly mirrors the existing DisableWrappers guard used for accessor generation. |
| test/unit/Elsa.Expressions.UnitTests/Handlers/GenerateWorkflowVariableAccessorsTests.cs | New regression tests cover the happy path (ExpandoObject in scope → import added) and the negative path (no ExpandoObject → import absent); missing a third test for the DisableWrappers = true branch. |
| test/unit/Elsa.Expressions.UnitTests/Elsa.Expressions.UnitTests.csproj | Adds Elsa.Expressions.CSharp project reference to the unit test project, required to compile the new handler tests. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[EvaluatingCSharp notification received] --> B[Get variables in scope]
B --> C{Any ExpandoObject\nvariables?}
C -- Yes --> D{DisableWrappers?}
D -- No --> E[Register System.Dynamic\nassembly + namespace import]
E --> F[Generate WorkflowVariablesProxy\nwith dynamic accessor]
D -- Yes --> G[Skip registration]
G --> H[Skip ExpandoObject accessor]
C -- No --> I[Generate WorkflowVariablesProxy\nwith typed accessor]
F --> J[AppendScript to notification]
I --> J
H --> J
Prompt To Fix All With AI
This is a comment left during a code review.
Path: test/unit/Elsa.Expressions.UnitTests/Handlers/GenerateWorkflowVariableAccessorsTests.cs
Line: 17-45
Comment:
**Missing test for `DisableWrappers = true` with an ExpandoObject variable**
The fix guards the registration with `if (hasExpandoVariables && !options.Value.DisableWrappers)`, but no test verifies the opposite side of that condition. When `DisableWrappers` is `true`, even if an `ExpandoObject` variable is in scope, neither the reference nor the `System.Dynamic` import should be added. Adding a third test case covering `CSharpOptions { DisableWrappers = true }` with an ExpandoObject variable would give full branch coverage over the new condition.
How can I resolve this? If you propose a fix, please make it concise.Reviews (2): Last reviewed commit: "chore: add trailing newline to regressio..." | Re-trigger Greptile
Fixes #7414
Purpose
This PR fixes a C# expression issue where JSON workflow variables exposed through the generated
Variablesaccessor could requireSystem.Dynamicwithout that namespace/reference being registered. It also adds focused regression tests for the affected accessor generation path.Scope
Bug fix (behavior change)
Description
Problem
RunCSharpcan access workflow variables through generated C# accessors in theVariablesglobal. When a workflow variable is JSON-backed and exposed asdynamic/ExpandoObject, the variable accessor generator introduces aSystem.Dynamicdependency into the generated script.Before this change, that dependency was not registered by the same feature path that generated the accessor, which could cause C# script compilation/evaluation failures when accessing JSON variables through
Variables.Solution
This change registers
System.Dynamicand theExpandoObjectassembly inside the workflow variable accessor generation path, but only when anExpandoObject-backed variable is actually present and wrappers are enabled.It also adds focused regression tests to verify that:
System.Dynamicis added when anExpandoObjectvariable is in scope.System.Dynamicis not added for non-JSON variable paths.Verification
UseCSharp().json.RunCSharpexpression that accesses the variable throughVariables, for exampleVariables.Customer.Name.Expected outcome:
The expression evaluates successfully without requiring manual
System.Dynamicregistration.Automated verification performed:
GenerateWorkflowVariableAccessors.dotnet test test/unit/Elsa.Expressions.UnitTests/Elsa.Expressions.UnitTests.csproj --no-restore --filter GenerateWorkflowVariableAccessorsTests.Screenshots / Recordings
Not applicable.
Commit Convention
This PR uses conventional commit messages:
fix: register System.Dynamic for C# JSON variable accessorstest: add C# variable accessor regression coverageChecklist