{"record":{"id":"fc02df0a4701a6ba","repo":"elsa-workflows/elsa-core","slug":"workflow-definition-validation-failed-errors","errorCode":null,"errorMessage":"Workflow definition validation failed: {errors}","messagePattern":"Workflow definition validation failed: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Platform.Integration/Steps/ImportWorkflowDefinitionStep.cs","lineNumber":76,"sourceCode":"        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()\n    {\n        if (!string.IsNullOrWhiteSpace(Path))\n        {\n            if (artifact.TryGetText(Path, out var content))\n                return content;\n\n            throw new InvalidOperationException($\"Workflow definition file '{Path}' was not found in the recipe artifact.\");\n        }\n\n        if (WorkflowDefinition.ValueKind == JsonValueKind.Object)\n            return WorkflowDefinition.GetRawText();\n","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Platform.Integration/Steps/ImportWorkflowDefinitionStep.cs#L58-L94","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the aggregated message: it lists all validation errors joined by '; ' and fix each reported issue in the workflow definition.","Ensure all activities, expressions, and referenced types used by the workflow are installed/registered in the target host before import.","Round-trip the definition through Elsa Studio or the workflow validator to catch issues before running the import step.","If errors are unclear, import the same JSON into a dev environment and inspect the full ValidationErrors collection."],"exampleFix":"// before\n\"activities\": [ { \"type\": \"MyCustomActivity\" } ] // type not registered on target\n// after\n// install the package providing MyCustomActivity, or use a built-in type\n\"activities\": [ { \"type\": \"Elsa.Http.SendHttpRequest\" } ]","handlingStrategy":"validation","validationCode":"var result = await importer.ValidateAsync(model, cancellationToken);\nif (!result.Succeeded)\n    foreach (var e in result.ValidationErrors) logger.LogError(\"Validation: {Message}\", e.Message);","typeGuard":null,"tryCatchPattern":"try\n{\n    await step.ExecuteAsync(context);\n}\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Workflow definition validation failed:\"))\n{\n    foreach (var issue in ex.Message[\"Workflow definition validation failed: \".Length..].Split(\"; \"))\n        logger.LogError(\"Validation issue: {Issue}\", issue);\n}","preventionTips":["Install all activity packages the workflow depends on before import.","Round-trip definitions through a validator/Studio before automated import.","Keep exporting and importing Elsa versions aligned."],"tags":["validation","workflow-import","workflow-definition"],"backgroundTag":"schema-validation-failed","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}