elsa-workflows/elsa-core · error · InvalidOperationException

Workflow definition validation failed

Error message

Workflow definition validation failed: {errors}

What it means

After importing, the step checks importResult.Succeeded. When the workflow definition was deserialized but failed semantic validation, the step aggregates all validation error messages into a single InvalidOperationException so the whole validation failure is visible at once.

Solutions

  1. Read the aggregated message: it lists all validation errors joined by '; ' and fix each reported issue in the workflow definition.
  2. Ensure all activities, expressions, and referenced types used by the workflow are installed/registered in the target host before import.
  3. Round-trip the definition through Elsa Studio or the workflow validator to catch issues before running the import step.
  4. If errors are unclear, import the same JSON into a dev environment and inspect the full ValidationErrors collection.

Example fix

// before
"activities": [ { "type": "MyCustomActivity" } ] // type not registered on target
// after
// install the package providing MyCustomActivity, or use a built-in type
"activities": [ { "type": "Elsa.Http.SendHttpRequest" } ]
Defensive patterns

Strategy: validation

Validate before calling

var result = await importer.ValidateAsync(model, cancellationToken);
if (!result.Succeeded)
    foreach (var e in result.ValidationErrors) logger.LogError("Validation: {Message}", e.Message);

Try / catch

try
{
    await step.ExecuteAsync(context);
}
catch (InvalidOperationException ex) when (ex.Message.StartsWith("Workflow definition validation failed:"))
{
    foreach (var issue in ex.Message["Workflow definition validation failed: ".Length..].Split("; "))
        logger.LogError("Validation issue: {Issue}", issue);
}

Prevention

When it happens

Trigger: Calling ImportAsync with a model that is structurally deserializable but semantically invalid: missing required fields, invalid activity references, unresolvable expression/variable references, or schema violations reported by the importer's ValidationErrors.

Common situations: Authoring workflow JSON by hand with invalid activity type names or missing required properties; importing definitions that reference custom activities not installed in the target host; schema drift between exporting and importing Elsa versions.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at src/modules/Elsa.Platform.Integration/Steps/ImportWorkflowDefinitionStep.cs:76

        try
        {
            model = apiSerializer.Deserialize<WorkflowDefinitionModel>(workflowJson);
        }
        catch (Exception ex) when (ex is JsonException or NotSupportedException or InvalidOperationException)
        {
            throw new InvalidOperationException("Workflow definition payload is invalid.", ex);
        }

        var importResult = await importer.ImportAsync(new SaveWorkflowDefinitionRequest
        {
            Model = model,
            Publish = Publish
        }, cancellationToken);

        if (!importResult.Succeeded)
        {
            var errors = string.Join("; ", importResult.ValidationErrors.Select(x => x.Message));
            throw new InvalidOperationException($"Workflow definition validation failed: {errors}");
        }

        context.Log($"Workflow definition '{model.DefinitionId}' was imported.");
    }

    private string ResolveWorkflowJson()
    {
        if (!string.IsNullOrWhiteSpace(Path))
        {
            if (artifact.TryGetText(Path, out var content))
                return content;

            throw new InvalidOperationException($"Workflow definition file '{Path}' was not found in the recipe artifact.");
        }

        if (WorkflowDefinition.ValueKind == JsonValueKind.Object)
            return WorkflowDefinition.GetRawText();

View on GitHub (pinned to fe9217bdfa)