elsa-workflows/elsa-core · error · OutputConversionException

Output conversion failed during result validation

Error message

Output conversion failed during result validation

What it means

An OutputConversionException thrown while validating the result of an output conversion. The converted value was null but the output descriptor's destination type does not allow null (AllowsNull is false). Elsa throws this so activity output contracts are enforced before downstream activities consume the value.

Solutions

  1. Ensure the activity actually sets the output value before completing (set the Output/Output<T> property in ExecuteAsync).
  2. Fix the expression/input that evaluates to null (check variable names, default values).
  3. If null is a legitimate result, mark the output as nullable (AllowsNull=true on the Output descriptor or use nullable type).
  4. Add validation before completion to fail fast with a clearer message.

Example fix

// before
public Output<string> Result { get; set; } = default!;
// ExecuteAsync never sets Result -> null conversion failure

// after
protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
{
    context.Set(Result, someValue ?? string.Empty); // or declare Output<string?> if null is valid
}
Defensive patterns

Strategy: validation

Validate before calling

// before completing the activity
var value = computedResult;
if (value is null && !outputDescriptor.AllowsNull)
    throw new InvalidOperationException("Output value must not be null; set the output or mark it nullable.");

Try / catch

// catch Elsa.Workflows.Core.Exceptions.OutputConversionException around activity execution
catch (OutputConversionException ex) when (ex.Stage == OutputConversionFailureStage.ResultValidation)
{
    logger.LogError(ex, "Output {Output} returned null for {ActivityType}", ex.OutputName, ex.ActivityType);
}

Prevention

When it happens

Trigger: An activity produces/sets an output whose value converts (or resolves) to null, while the output descriptor for the target output declares a non-nullable destination type or AllowNull=false; thrown from output conversion/result validation in ActivityExecutionContext.

Common situations: An expression evaluated to null (missing variable, empty input), a C# activity output property left unset while declared non-nullable, custom activities with output descriptors copied from nullable types but declared non-nullable, or a converter returning null for a failed parse.

Related errors


AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13). Data as JSON: /api/errors/db3b2d5731cbd32c. Report an issue: GitHub.

Appendix: source

Thrown at src/modules/Elsa.Workflows.Core/Contexts/ActivityExecutionContext.cs:815

        if (destination == null)
        {
            throw new OutputConversionException(
                output.Converter.Id,
                OutputConversionFailureStage.Resolution,
                Activity.Id,
                Activity.Type,
                resolvedOutputName,
                output.MemoryBlockReference().Id,
                sourceType,
                null);
        }

        if (value == null)
        {
            if (!destination.AllowsNull)
            {
                throw new OutputConversionException(
                    output.Converter.Id,
                    OutputConversionFailureStage.ResultValidation,
                    Activity.Id,
                    Activity.Type,
                    resolvedOutputName,
                    destination.Id,
                    sourceType,
                    destination.Type);
            }

            ExpressionExecutionContext.SetBoundValue(output, null);
            return;
        }

        var converterInvoker = GetRequiredService<IOutputConverterInvoker>();
        var convertedValue = converterInvoker.Invoke(this, output, resolvedOutputName, sourceType, value, destination);
        ExpressionExecutionContext.SetBoundValue(output, convertedValue);
    }

View on GitHub (pinned to fe9217bdfa)