Skip to content

[SDK] ForEach documentation example with JArray.Parse() throws NotImplementedException at runtime #1544

Description

@CamyDee

Describe the Bug

The official documentation for WorkflowControlActions.ForEach
at https://learn.microsoft.com/en-us/azure/logic-apps/standard-sdk/workflow-control-actions-class-definition
shows this example:

var forEach = WorkflowActions.BuiltIn.Control.ForEach(
    items: () => JArray.Parse("[\"one\",\"two\"]"),
    actions: (item) => WorkflowActions.BuiltIn
        .Compose(inputs: () => $"Item: {item}")
        .WithName("ProcessItem")
).WithName("LoopItems");

This compiles but throws at runtime:

System.NotImplementedException:
Can't convert call to method
Newtonsoft.Json.Linq.JArray Parse(System.String): Parse("[]")

The expression tree converter cannot handle method calls
(JArray.Parse(...)) inside lambda expressions. Similarly,
new JArray() also fails with a different
NotImplementedException from ComplexObjectConverter.Visit.

Plan Type

Standard

Steps to Reproduce the Bug or Issue

To Reproduce

  1. Create a codeful workflow project per the SDK docs
  2. Use the exact ForEach example from the documentation
  3. Run the project
  4. Observe the runtime exception

Expected behavior

The documented example should work at runtime. If JArray.Parse
is not supported in expression trees, the documentation should
show the correct pattern (e.g., referencing a previous action's
.Body output or using a supported expression form).

Actual behavior

NotImplementedException thrown by
LogicExpressionConverter.Visit(MethodCallExpression).

Workaround

Use a string literal cast to JToken:

var forEach = WorkflowActions.BuiltIn.Control.ForEach(
    items: () => (JToken)"placeholder",
    actions: (item) => ...);

This generates "Foreach": "placeholder" in the JSON. For real
usage, reference a typed action's output (e.g., http.Body).

Workflow JSON

Screenshots or Videos

No response

Additional context

Environment

  • Microsoft.Azure.Workflows.Sdk: 1.0.0-preview.1
  • .NET: net8.0
  • OS: Windows 11
  • Docs page: workflow-control-actions-class-definition

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions