OrchardCMS/OrchardCore · error · ArgumentException

A Content Item was expected

Error message

A Content Item was expected

What it means

The Liquid `container` filter expects its input to be a ContentItem. It casts input.ToObjectValue() to ContentItem and throws ArgumentException('A Content Item was expected') when the cast fails, i.e. the value is not a ContentItem (null or another object type).

Solutions

  1. Ensure the input is a ContentItem object (e.g. from `contents` API, a fetch of the item, or another filter returning ContentItem), not an ID string
  2. If you only have an ID, load the item first (e.g. via a liquid filter that returns the item) before applying `container`
  3. Guard with `{% if myItem %}{{ myItem | container }}{% endif %}` to skip nil values

Example fix

// before
{{ '4ynrtxw0phcnqvyv' | container }}
// after
{% assign blog = Blogs['my-blog'] %}{{ blog | container }}
Defensive patterns

Strategy: type-guard

Validate before calling

{% if myItem %}{{ myItem | container }}{% endif %}

Type guard

bool IsContentItem(object v) => v is ContentItem;

Try / catch

try { result = await filter.ProcessAsync(input, args, ctx); } catch (ArgumentException ex) when (ex.Message == "A Content Item was expected") { log.Warn("container filter input was not a ContentItem: {Type}", input?.GetType().Name); }

Prevention

When it happens

Trigger: Calling `{{ someValue | container }}` in Liquid where someValue is nil, a string content item id, a ContentItemResult, or any object other than an actual ContentItem instance.

Common situations: Passing a content item ID string instead of the item object; using the filter on a variable that was never assigned (nil); using a value from a query that returns shapes/projections rather than ContentItem objects.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/662b82b7470229ba. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore.Modules/OrchardCore.Lists/Liquid/ContainerFilter.cs:20

using Fluid.Values;
using OrchardCore.ContentManagement;
using OrchardCore.Liquid;
using OrchardCore.Lists.Models;

namespace OrchardCore.Lists.Liquid;

public class ContainerFilter : ILiquidFilter
{
    private readonly IContentManager _contentManager;

    public ContainerFilter(IContentManager contentManager)
    {
        _contentManager = contentManager;
    }

    public async ValueTask<FluidValue> ProcessAsync(FluidValue input, FilterArguments arguments, LiquidTemplateContext ctx)
    {
        var contentItem = input.ToObjectValue() as ContentItem ?? throw new ArgumentException("A Content Item was expected");

        var containerId = contentItem.TryGet<ContainedPart>(out var containedPart) ? containedPart.ListContentItemId : null;

        if (containerId != null)
        {
            var container = await _contentManager.GetAsync(containerId);

            if (container != null)
            {
                return new ObjectValue(container);
            }
        }

        return new ObjectValue(contentItem);
    }
}

View on GitHub (pinned to 4306c0717f)