{"record":{"id":"ca5611e87d2c615f","repo":"OrchardCMS/OrchardCore","slug":"the-unpublishcontenttask-failed-to-retrieve-the-content-item","errorCode":null,"errorMessage":"The 'UnpublishContentTask' failed to retrieve the content item.","messagePattern":"The 'UnpublishContentTask' failed to retrieve the content item\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UnpublishContentTask.cs","lineNumber":32,"sourceCode":"        IWorkflowScriptEvaluator scriptEvaluator,\n        IStringLocalizer<UnpublishContentTask> localizer)\n        : base(contentManager, scriptEvaluator, localizer)\n    {\n    }\n\n    public override string Name => nameof(UnpublishContentTask);\n\n    public override LocalizedString DisplayText => S[\"Unpublish Content Task\"];\n\n    public override LocalizedString Category => S[\"Content\"];\n\n    public override IEnumerable<Outcome> GetPossibleOutcomes(WorkflowExecutionContext workflowContext, ActivityContext activityContext)\n        => Outcome(S[\"Unpublished\"], S[\"Noop\"]);\n\n    public override async Task<ActivityExecutionResult> ExecuteAsync(WorkflowExecutionContext workflowContext, ActivityContext activityContext)\n    {\n        var content = (await GetContentAsync(workflowContext))\n            ?? throw new InvalidOperationException($\"The '{nameof(UnpublishContentTask)}' failed to retrieve the content item.\");\n\n        if (string.Equals(InlineEvent.ContentItemId, content.ContentItem.ContentItemId, StringComparison.OrdinalIgnoreCase))\n        {\n            return Outcome(\"Noop\");\n        }\n\n        var contentItem = await ContentManager.GetAsync(content.ContentItem.ContentItemId, VersionOptions.Latest);\n\n        if (contentItem == null)\n        {\n            if (content is ContentItemIdExpressionResult)\n            {\n                throw new InvalidOperationException($\"The '{nameof(UnpublishContentTask)}' failed to retrieve the content item.\");\n            }\n\n            contentItem = content.ContentItem;\n        }\n","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UnpublishContentTask.cs#L14-L50","documentation":"UnpublishContentTask calls GetContentAsync(workflowContext) to resolve the target content item; if it returns null the activity cannot proceed and throws InvalidOperationException. This protects against unpublishing an unresolvable target.","triggerScenarios":"The activity's ContentItemId expression (or ContentItem expression) evaluates to null — empty field, misspelled workflow variable, or the preceding event provided no content item input.","commonSituations":"Designer left the content item field blank; workflow was started by a non-content trigger (e.g. timer) with no content item in context.","solutions":["Set a valid ContentItemId or ContentItem expression on the UnpublishContentTask activity.","Ensure an earlier activity populates the referenced workflow variable.","When the workflow starts from a content event, rely on the event's content item input instead of a manual expression.","Add a condition before the task to skip it when the variable is empty."],"exampleFix":"// before\nContentItemId: \"\" \n// after\nContentItemId: \"{{ Workflow.Input.ContentItem.ContentItemId }}\"","handlingStrategy":"validation","validationCode":"// In a condition before the task:\nvar resolved = await GetContentAsync(workflowContext);\nif (resolved is null) throw new InvalidOperationException(\"UnpublishContentTask: no content item resolved from the configured expression.\");","typeGuard":null,"tryCatchPattern":"try { await task.ExecuteAsync(workflowContext, activityContext); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"failed to retrieve the content item\"))\n{\n    logger.LogWarning(ex, \"Unpublish skipped: no resolvable content item.\");\n}","preventionTips":["Set ContentItemId/ContentItem expressions explicitly in the activity.","For non-content triggers, load or pass the item explicitly.","Verify expression output with a Log task during development.","Skip the task via a condition when the variable is empty."],"tags":["workflows","content","configuration","null-value"],"backgroundTag":"missing-required-argument","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}