{"record":{"id":"db3b2d5731cbd32c","repo":"elsa-workflows/elsa-core","slug":"output-conversion-failed-during-result-validation","errorCode":null,"errorMessage":"Output conversion failed during result validation","messagePattern":"Output conversion failed during result validation","errorType":"exception","errorClass":"OutputConversionException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Workflows.Core/Contexts/ActivityExecutionContext.cs","lineNumber":815,"sourceCode":"\n        if (destination == null)\n        {\n            throw new OutputConversionException(\n                output.Converter.Id,\n                OutputConversionFailureStage.Resolution,\n                Activity.Id,\n                Activity.Type,\n                resolvedOutputName,\n                output.MemoryBlockReference().Id,\n                sourceType,\n                null);\n        }\n\n        if (value == null)\n        {\n            if (!destination.AllowsNull)\n            {\n                throw new OutputConversionException(\n                    output.Converter.Id,\n                    OutputConversionFailureStage.ResultValidation,\n                    Activity.Id,\n                    Activity.Type,\n                    resolvedOutputName,\n                    destination.Id,\n                    sourceType,\n                    destination.Type);\n            }\n\n            ExpressionExecutionContext.SetBoundValue(output, null);\n            return;\n        }\n\n        var converterInvoker = GetRequiredService<IOutputConverterInvoker>();\n        var convertedValue = converterInvoker.Invoke(this, output, resolvedOutputName, sourceType, value, destination);\n        ExpressionExecutionContext.SetBoundValue(output, convertedValue);\n    }","sourceCodeStart":797,"sourceCodeEnd":833,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Workflows.Core/Contexts/ActivityExecutionContext.cs#L797-L833","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the activity actually sets the output value before completing (set the Output/Output<T> property in ExecuteAsync).","Fix the expression/input that evaluates to null (check variable names, default values).","If null is a legitimate result, mark the output as nullable (AllowsNull=true on the Output descriptor or use nullable type).","Add validation before completion to fail fast with a clearer message."],"exampleFix":"// before\npublic Output<string> Result { get; set; } = default!;\n// ExecuteAsync never sets Result -> null conversion failure\n\n// after\nprotected override async ValueTask ExecuteAsync(ActivityExecutionContext context)\n{\n    context.Set(Result, someValue ?? string.Empty); // or declare Output<string?> if null is valid\n}","handlingStrategy":"validation","validationCode":"// before completing the activity\nvar value = computedResult;\nif (value is null && !outputDescriptor.AllowsNull)\n    throw new InvalidOperationException(\"Output value must not be null; set the output or mark it nullable.\");","typeGuard":null,"tryCatchPattern":"// catch Elsa.Workflows.Core.Exceptions.OutputConversionException around activity execution\ncatch (OutputConversionException ex) when (ex.Stage == OutputConversionFailureStage.ResultValidation)\n{\n    logger.LogError(ex, \"Output {Output} returned null for {ActivityType}\", ex.OutputName, ex.ActivityType);\n}","preventionTips":["Always set declared outputs in ExecuteAsync before completion.","Declare outputs nullable (Output<T?>) when null is a valid result.","Test custom activities end-to-end so conversion validation runs."],"tags":["workflow","output","null-validation","csharp"],"backgroundTag":"null-argument","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}