{"record":{"id":"853a12221fe5a472","repo":"elsa-workflows/elsa-core","slug":"workflow-definition-payload-is-invalid","errorCode":null,"errorMessage":"Workflow definition payload is invalid.","messagePattern":"Workflow definition payload is invalid\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Platform.Integration/Steps/ImportWorkflowDefinitionStep.cs","lineNumber":64,"sourceCode":"                    $\"Workflow definition file '{Path}' was not found in the recipe artifact.\",\n                    context.Target(\"input.path\"))\n            ]);\n        }\n\n        return ValueTask.FromResult<IReadOnlyList<RecipeDiagnostic>>([]);\n    }\n\n    public async ValueTask ExecuteAsync(StepContext context, CancellationToken cancellationToken = default)\n    {\n        var workflowJson = ResolveWorkflowJson();\n        WorkflowDefinitionModel model;\n        try\n        {\n            model = apiSerializer.Deserialize<WorkflowDefinitionModel>(workflowJson);\n        }\n        catch (Exception ex) when (ex is JsonException or NotSupportedException or InvalidOperationException)\n        {\n            throw new InvalidOperationException(\"Workflow definition payload is invalid.\", ex);\n        }\n\n        var importResult = await importer.ImportAsync(new SaveWorkflowDefinitionRequest\n        {\n            Model = model,\n            Publish = Publish\n        }, cancellationToken);\n\n        if (!importResult.Succeeded)\n        {\n            var errors = string.Join(\"; \", importResult.ValidationErrors.Select(x => x.Message));\n            throw new InvalidOperationException($\"Workflow definition validation failed: {errors}\");\n        }\n\n        context.Log($\"Workflow definition '{model.DefinitionId}' was imported.\");\n    }\n\n    private string ResolveWorkflowJson()","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Platform.Integration/Steps/ImportWorkflowDefinitionStep.cs#L46-L82","documentation":"ImportWorkflowDefinitionStep deserializes the resolved workflow JSON into a WorkflowDefinitionModel using the API serializer. If the payload is not well-formed JSON or cannot be deserialized (JsonException, NotSupportedException, InvalidOperationException), the step wraps the failure in this InvalidOperationException to give a single, clear import error while preserving the inner exception.","triggerScenarios":"Executing the import step with malformed JSON, JSON that is not an object matching WorkflowDefinitionModel (e.g. an array or string), or a shape from an incompatible Elsa version whose serializer throws NotSupportedException.","commonSituations":"Hand-editing a workflow export and breaking JSON syntax; pointing the step at the wrong artifact file (not a workflow definition); exporting from a newer/older Elsa version with a changed model schema.","solutions":["Validate the workflow JSON with a JSON parser and compare its structure against a known-good WorkflowDefinitionModel export.","Re-export the workflow definition from a compatible Elsa Studio/CLI version so the model schema matches this runtime.","Check ResolveWorkflowJson inputs: confirm Path points at the right artifact entry or WorkflowDefinition holds a JSON object, not another file type.","Inspect the inner exception (ex.InnerException) for the exact JSON parse error and the offending offset/token."],"exampleFix":"// before\nstep.WorkflowDefinition = \"not-json-at-all\";\n// after\nstep.WorkflowDefinition = System.Text.Json.JsonDocument.Parse(File.ReadAllText(\"workflow.json\")).RootElement;","handlingStrategy":"validation","validationCode":"try { using var _ = System.Text.Json.JsonDocument.Parse(workflowJson); }\ncatch (System.Text.Json.JsonException ex)\n{\n    throw new InvalidOperationException(\"Workflow JSON is not valid before import.\", ex);\n}","typeGuard":"static bool IsJsonObject(string json) =>\n    System.Text.Json.JsonDocument.Parse(json).RootElement.ValueKind == System.Text.Json.JsonValueKind.Object;","tryCatchPattern":"try\n{\n    await step.ExecuteAsync(context);\n}\ncatch (InvalidOperationException ex) when (ex.Message == \"Workflow definition payload is invalid.\")\n{\n    logger.LogError(ex.InnerException, \"Deserialization failed: {Reason}\", ex.InnerException?.Message);\n}","preventionTips":["Always export workflow JSON from the same Elsa version that imports it.","Lint/parse the JSON before importing.","Don't hand-edit exports without re-validating."],"tags":["json","serialization","workflow-import","validation"],"backgroundTag":"json-parse-error","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}