{"record":{"id":"7796e2f44cb7e753","repo":"OrchardCMS/OrchardCore","slug":"the-deletecontenttask-failed-to-retrieve-the-content-item","errorCode":null,"errorMessage":"The 'DeleteContentTask' failed to retrieve the content item.","messagePattern":"The 'DeleteContentTask' failed to retrieve the content item\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/DeleteContentTask.cs","lineNumber":31,"sourceCode":"        IWorkflowScriptEvaluator scriptEvaluator,\n        IStringLocalizer<DeleteContentTask> localizer)\n        : base(contentManager, scriptEvaluator, localizer)\n    {\n    }\n\n    public override string Name => nameof(DeleteContentTask);\n\n    public override LocalizedString DisplayText => S[\"Delete Content Task\"];\n\n    public override LocalizedString Category => S[\"Content\"];\n\n    public override IEnumerable<Outcome> GetPossibleOutcomes(WorkflowExecutionContext workflowContext, ActivityContext activityContext)\n        => Outcome(S[\"Deleted\"], 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(DeleteContentTask)}' 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(DeleteContentTask)}' failed to retrieve the content item.\");\n            }\n\n            contentItem = content.ContentItem;\n        }\n","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/DeleteContentTask.cs#L13-L49","documentation":"DeleteContentTask.ExecuteAsync calls GetContentAsync to resolve the content item from the workflow context or a configured expression; if it returns null the task throws this InvalidOperationException. It means no content item could be resolved for deletion — the expression evaluated to nothing or referenced a missing item.","triggerScenarios":"DeleteContentTask with a ContentItem expression that evaluates to null, or a ContentItemIdExpressionResult whose ID does not match any existing item, during ExecuteAsync.","commonSituations":"Typo or wrong property path in the expression; the item was already deleted by a prior workflow step; Liquid/Javascript expression returns an object of the wrong shape so the resolved content is null.","solutions":["Fix the ContentItem/ContentItemId expression so it resolves a real content item (verify the property name and that the item exists).","Ensure upstream workflow activities actually set the ContentItem/ContentItemId on the workflow context before DeleteContentTask runs.","Guard the workflow with a condition activity that checks the resolved value is non-null before the delete step.","Catch InvalidOperationException in host code around workflow execution and log which activity failed."],"exampleFix":"// before: expression points at a non-existent property\nContentItem = '{{ Workflow.Input.\"ContenItem\" }}'\n// after\nContentItem = '{{ Workflow.Input.\"ContentItem\" }}'","handlingStrategy":"validation","validationCode":"// Before the workflow runs, resolve the expression yourself\nvar item = await expressionEvaluator.EvaluateAsync(taskExpression, workflowContext) as ContentItem;\nif (item is null)\n    throw new InvalidOperationException(\"DeleteContentTask expression resolves to no content item.\");","typeGuard":"// C# narrowing\nstatic bool HasContentItem(object value) => value is ContentItem { ContentItemId: > 0 };","tryCatchPattern":"try { await workflowManager.TriggerEventAsync(eventName, contentItem); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"DeleteContentTask\") && ex.Message.Contains(\"failed to retrieve\"))\n{\n    logger.LogWarning(ex, \"Delete skipped: no content item resolved.\");\n}","preventionTips":["Test workflow expressions in the editor before deploying; typos silently evaluate to null.","Ensure the triggering activity provides the ContentItem in the workflow context.","Check for prior delete steps in the same workflow that consume the item.","Use condition activities to verify the item exists before destructive tasks."],"tags":["orchardcore","workflows","contents","null-reference"],"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-23T08:17:48.524Z"}