{"record":{"id":"662b82b7470229ba","repo":"OrchardCMS/OrchardCore","slug":"a-content-item-was-expected","errorCode":null,"errorMessage":"A Content Item was expected","messagePattern":"A Content Item was expected","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.Lists/Liquid/ContainerFilter.cs","lineNumber":20,"sourceCode":"using Fluid.Values;\nusing OrchardCore.ContentManagement;\nusing OrchardCore.Liquid;\nusing OrchardCore.Lists.Models;\n\nnamespace OrchardCore.Lists.Liquid;\n\npublic class ContainerFilter : ILiquidFilter\n{\n    private readonly IContentManager _contentManager;\n\n    public ContainerFilter(IContentManager contentManager)\n    {\n        _contentManager = contentManager;\n    }\n\n    public async ValueTask<FluidValue> ProcessAsync(FluidValue input, FilterArguments arguments, LiquidTemplateContext ctx)\n    {\n        var contentItem = input.ToObjectValue() as ContentItem ?? throw new ArgumentException(\"A Content Item was expected\");\n\n        var containerId = contentItem.TryGet<ContainedPart>(out var containedPart) ? containedPart.ListContentItemId : null;\n\n        if (containerId != null)\n        {\n            var container = await _contentManager.GetAsync(containerId);\n\n            if (container != null)\n            {\n                return new ObjectValue(container);\n            }\n        }\n\n        return new ObjectValue(contentItem);\n    }\n}\n","sourceCodeStart":2,"sourceCodeEnd":37,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Lists/Liquid/ContainerFilter.cs#L2-L37","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["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","If you only have an ID, load the item first (e.g. via a liquid filter that returns the item) before applying `container`","Guard with `{% if myItem %}{{ myItem | container }}{% endif %}` to skip nil values"],"exampleFix":"// before\n{{ '4ynrtxw0phcnqvyv' | container }}\n// after\n{% assign blog = Blogs['my-blog'] %}{{ blog | container }}","handlingStrategy":"type-guard","validationCode":"{% if myItem %}{{ myItem | container }}{% endif %}","typeGuard":"bool IsContentItem(object v) => v is ContentItem;","tryCatchPattern":"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); }","preventionTips":["Verify variables hold ContentItem objects, not IDs or shapes, before using content filters","Use {% assign %} from filters that return ContentItem (e.g. contents) rather than raw strings","Test Liquid templates against nil inputs","Read the filter's documentation for the expected input type"],"tags":["liquid","fluid","contentitem","type-mismatch"],"backgroundTag":"incompatible-source-type","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"}