{"record":{"id":"1d3f11be3ca387d0","repo":"OrchardCMS/OrchardCore","slug":"content-item-not-found","errorCode":null,"errorMessage":"Content item not found","messagePattern":"Content item not found","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.Contents/ViewComponents/DisplayContentItemViewComponent.cs","lineNumber":35,"sourceCode":"        IUpdateModelAccessor modelUpdaterAccessor)\n    {\n        _contentItemDisplayManager = contentItemDisplayManager;\n        _contentManager = contentManager;\n        _modelUpdaterAccessor = modelUpdaterAccessor;\n    }\n\n    public async Task<IViewComponentResult> InvokeAsync(string contentItemId = null, string displayType = null)\n    {\n        ContentItem contentItem = null;\n\n        if (contentItemId != null)\n        {\n            contentItem = await _contentManager.GetAsync(contentItemId);\n        }\n\n        if (contentItem == null)\n        {\n            throw new ArgumentException(\"Content item not found\");\n        }\n\n        var model = await _contentItemDisplayManager.BuildDisplayAsync(contentItem, _modelUpdaterAccessor.ModelUpdater, displayType);\n\n        return View(model);\n    }\n}\n","sourceCodeStart":17,"sourceCodeEnd":43,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Contents/ViewComponents/DisplayContentItemViewComponent.cs#L17-L43","documentation":"DisplayContentItemViewComponent.InvokeAsync loads the content item by id through IContentManager (versioned or published overload depending on the parameter) and throws an ArgumentException when no item is found, because a display cannot be built for a null item.","triggerScenarios":"Rendering the content item view component (e.g. via @(await Component.InvokeAsync<DisplayContentItemViewComponent>(...)) or the VC tag helper) with a contentItemId that does not exist, was deleted, or is not visible in the requested version/publish state.","commonSituations":"Hard-coded or stale content item ids in templates after content was deleted; ids read from query strings without checking; draft items requested in published-only mode.","solutions":["Verify the contentItemId exists (and is published/loaded as requested) before rendering the component.","Check with IContentManager.GetAsync(contentItemId) first and render a friendly message when null.","If the id comes from user input, treat a miss as a 404/empty state instead of letting the view component throw.","Fix stale hard-coded ids after content deletions or environment restores."],"exampleFix":"// before\n@(await Component.InvokeAsync<DisplayContentItemViewComponent>(new { contentItemId = Model.Id, displayType = \"Detail\" }))\n// after\nvar item = await contentManager.GetAsync(Model.Id);\n@if (item is not null)\n{\n    @(await Component.InvokeAsync<DisplayContentItemViewComponent>(new { contentItemId = Model.Id, displayType = \"Detail\" }))\n}","handlingStrategy":"validation","validationCode":"// C#\nvar item = await contentManager.GetAsync(contentItemId);\nif (item is null)\n{\n    // render empty state or 404 instead of invoking the view component\n    return NotFound();\n}","typeGuard":"bool HasContentItem(ContentItem item) => item is not null;","tryCatchPattern":"try\n{\n    var result = await Component.InvokeAsync<DisplayContentItemViewComponent>(new { contentItemId = id, displayType = \"Detail\" });\n}\ncatch (ArgumentException)\n{\n    // content item missing: show fallback content\n}","preventionTips":["Never hard-code content item ids; resolve them by alias or query first.","Treat ids from query strings as untrusted and check existence before display.","Be aware of publish-state/draft visibility when loading by id.","After content deletions or restores, audit templates that reference item ids."],"tags":["view-components","content-items","entity-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"}