OrchardCMS/OrchardCore · error · ArgumentException
Content item not found
Error message
Content item not found
What it means
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.
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.
Example fix
// before
@(await Component.InvokeAsync<DisplayContentItemViewComponent>(new { contentItemId = Model.Id, displayType = "Detail" }))
// after
var item = await contentManager.GetAsync(Model.Id);
@if (item is not null)
{
@(await Component.InvokeAsync<DisplayContentItemViewComponent>(new { contentItemId = Model.Id, displayType = "Detail" }))
} Defensive patterns
Strategy: validation
Validate before calling
// C#
var item = await contentManager.GetAsync(contentItemId);
if (item is null)
{
// render empty state or 404 instead of invoking the view component
return NotFound();
} Type guard
bool HasContentItem(ContentItem item) => item is not null;
Try / catch
try
{
var result = await Component.InvokeAsync<DisplayContentItemViewComponent>(new { contentItemId = id, displayType = "Detail" });
}
catch (ArgumentException)
{
// content item missing: show fallback content
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- The cloned content item doesn't contain an AutoroutePart.
- The part doesn't exist
- string.Join(", ", result.Errors)
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/1d3f11be3ca387d0.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore.Modules/OrchardCore.Contents/ViewComponents/DisplayContentItemViewComponent.cs:35
IUpdateModelAccessor modelUpdaterAccessor)
{
_contentItemDisplayManager = contentItemDisplayManager;
_contentManager = contentManager;
_modelUpdaterAccessor = modelUpdaterAccessor;
}
public async Task<IViewComponentResult> InvokeAsync(string contentItemId = null, string displayType = null)
{
ContentItem contentItem = null;
if (contentItemId != null)
{
contentItem = await _contentManager.GetAsync(contentItemId);
}
if (contentItem == null)
{
throw new ArgumentException("Content item not found");
}
var model = await _contentItemDisplayManager.BuildDisplayAsync(contentItem, _modelUpdaterAccessor.ModelUpdater, displayType);
return View(model);
}
}
View on GitHub (pinned to 4306c0717f)