Skip to content
LambogeniusDocs

Compose using Liquid for Azure Logic Apps

C# helpers

The csharp block, CallCSharp, what helpers may do, and how they are compiled and stopped.

Service provider/serviceProviders/lamboLiquidComposeOperation ComposeLiquid, shown in the designer as Compose using Liquid.

A block of helper methods

Put one {% csharp %} … {% endcsharp %} block at the very top of the template and call its methods with CallCSharp. The action needs "enableScripts": true, and the app needs LiquidCompose__AllowScripts=true.

{% csharp %}
public string NormalizeCode(string value)
{
    return (value ?? "").Trim().ToUpperInvariant();
}

public string Money(double amount)
{
    return amount.ToString("0.00", CultureInfo.InvariantCulture);
}
{% endcsharp %}
{
  "orderNumber": {{ content.order.number | CallCSharp: 'NormalizeCode' | ToJson }},
  "total": {{ content.order.total | CallCSharp: 'Money' | ToJson }},
  "reference": {{ content.order.reference | Default: '' | CallCSharp: 'NormalizeCode' | ToJson }}
}

What helpers may be

  • Public instance methods with one string, double or bool parameter, returning one of those types. Private methods, fields and const are allowed.
  • Namespaces in scope: System, System.Collections.Generic, System.Globalization, System.Linq, System.Text and System.Text.RegularExpressions. C# 12.
  • No I/O: helpers compile against a fixed reference set, without System.IO, HttpClient, Process or Console. Use CallFunction for lookups.
  • One block, in the root template. Blocks in partials, a second block, overloads, generics or two parameters fail with TemplateSyntaxError or UnsupportedScriptFeature.

Values in and out

  • JSON numbers become double; strings are never parsed into numbers or Booleans.
  • A null or missing value fails with ScriptExecutionFailed. Put Default: '' before CallCSharp for optional fields.
  • Default turns values into strings, so don't use it before a helper that takes a double or a bool.
  • A helper that throws fails the action with the helper's name and the exception type, never its message, which may contain data.

Compiled once, stopped at the deadline

The first run of a template compiles its block with Roslyn, which can take a few seconds on a fresh worker; later runs use the cached assembly. timeoutSeconds includes that compile, so leave room for it. A helper that never returns is stopped at the deadline with TransformationTimeout; its worker is replaced and the next run works normally.