{"record":{"id":"9e83816536bf7319","repo":"OrchardCMS/OrchardCore","slug":"the-retrievecontenttask-failed-to-retrieve-the-content-item","errorCode":null,"errorMessage":"The 'RetrieveContentTask' failed to retrieve the content item.","messagePattern":"The 'RetrieveContentTask' failed to retrieve the content item\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/RetrieveContentTask.cs","lineNumber":36,"sourceCode":"    {\n    }\n\n    public override string Name => nameof(RetrieveContentTask);\n\n    public override LocalizedString DisplayText => S[\"Retrieve Content Task\"];\n\n    public override LocalizedString Category => S[\"Content\"];\n\n    public override IEnumerable<Outcome> GetPossibleOutcomes(WorkflowExecutionContext workflowContext, ActivityContext activityContext)\n        => Outcome(S[\"Retrieved\"]);\n\n    public override async Task<ActivityExecutionResult> ExecuteAsync(WorkflowExecutionContext workflowContext, ActivityContext activityContext)\n    {\n        var contentItemId = (await GetContentItemIdAsync(workflowContext))\n            ?? throw new InvalidOperationException($\"The '{nameof(RetrieveContentTask)}' failed to evaluate the 'ContentItemId'.\");\n\n        var contentItem = (await ContentManager.GetAsync(contentItemId, VersionOptions.Latest))\n            ?? throw new InvalidOperationException($\"The '{nameof(RetrieveContentTask)}' failed to retrieve the content item.\");\n\n        if (string.IsNullOrEmpty(workflowContext.CorrelationId))\n        {\n            workflowContext.CorrelationId = contentItem.ContentItemId;\n        }\n\n        workflowContext.Properties[ContentEventConstants.ContentItemInputKey] = contentItem;\n        workflowContext.LastResult = contentItem;\n\n        return Outcome(\"Retrieved\");\n    }\n}\n","sourceCodeStart":18,"sourceCodeEnd":49,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/RetrieveContentTask.cs#L18-L49","documentation":"RetrieveContentTask resolved a ContentItemId but IContentManager.GetAsync(id, VersionOptions.Latest) returned null, meaning no content item with that ID exists. The library throws to abort the activity rather than operating on a missing item.","triggerScenarios":"The evaluated content item ID does not match any persisted content item (deleted item, wrong ID string, wrong tenant, or unpublished item removed before the workflow ran).","commonSituations":"Content was deleted between trigger and execution, ID was copied from another environment, or a workflow variable holds a stale/incorrect ID.","solutions":["Verify the content item exists for the current tenant with that exact ContentItemId.","Check that the ID expression yields the correct ID (log it before this task).","Guard the workflow: only run this task when the content item is known to exist (e.g. triggered by a content event for that item).","If deletion is expected, add a fallback path or use a try/catch-style error outcome in the workflow."],"exampleFix":"// before\nContentItemId: \"{{ Workflow.Input.Foo.Id }}\" // wrong source\n// after\nContentItemId: \"{{ Workflow.Input.ContentItem.ContentItemId }}\"","handlingStrategy":"validation","validationCode":"var item = await contentManager.GetAsync(id, VersionOptions.Latest);\nif (item is null) throw new InvalidOperationException($\"Content item '{id}' does not exist; workflow cannot retrieve it.\");","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, \"Target content item no longer exists.\");\n    return; // or take fallback path\n}","preventionTips":["Confirm the referenced item exists before running the workflow (existence condition).","Avoid hardcoding ContentItemIds across environments.","Account for deletion race conditions with fallback handling.","Use the content event's own item instead of separate lookups when possible."],"tags":["workflows","content","not-found"],"backgroundTag":"entity-not-found","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"}