OrchardCMS/OrchardCore · error · ArgumentException

The name attribute can't be empty

Error message

The name attribute can't be empty

What it means

ZoneTagHelper creates or retrieves a named zone on the layout when a <zone> element is processed. The Name attribute is mandatory: if it is missing or empty, ProcessAsync throws ArgumentException immediately. This ensures zones are always addressable by a non-empty key in ThemeLayout.Zones.

Solutions

  1. Add a non-empty Name attribute: <zone Name="Content" />
  2. If the name is dynamic, validate it is non-empty before rendering the zone tag
  3. Check attribute casing — the tag helper property is Name
  4. Guard the razor code: only emit the <zone> element when the computed name is present

Example fix

// before
<zone Name="@Model.ZoneName"></zone>
// after
@if (!string.IsNullOrEmpty(Model.ZoneName))
{
    <zone Name="@Model.ZoneName"></zone>
}
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(zoneName)) { throw new ArgumentException("Zone name must be provided", nameof(zoneName)); }
// then render: <zone Name="@zoneName"></zone>

Try / catch

try { await next(output); } catch (ArgumentException e) when (e.Message.Contains("name attribute")) { output.SuppressOutput(); }

Prevention

When it happens

Trigger: Writing <zone></zone> or <zone Name=""></zone> in a Razor template, or binding Name to a model property/variable that evaluates to null or empty string at render time.

Common situations: Forgotten Name attribute; dynamic Name="@Model.ZoneName" where the value is empty; typos like name="" (case/wrong attribute casing not mapped to the helper property).

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at src/OrchardCore/OrchardCore.DisplayManagement/TagHelpers/ZoneTagHelper.cs:33

    private readonly ILogger _logger;

    public ZoneTagHelper(ILayoutAccessor layoutAccessor, ILogger<ZoneTagHelper> logger)
    {
        _layoutAccessor = layoutAccessor;
        _logger = logger;
    }

    [HtmlAttributeName(PositionAttribute)]
    public string Position { get; set; }

    [HtmlAttributeName(NameAttribute)]
    public string Name { get; set; }

    public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
    {
        if (string.IsNullOrEmpty(Name))
        {
            throw new ArgumentException("The name attribute can't be empty");
        }

        var childContent = await output.GetChildContentAsync();
        var layout = await _layoutAccessor.GetLayoutAsync();

        var zone = layout.Zones[Name];

        if (zone is Shape shape)
        {
            await shape.AddAsync(childContent, Position);
        }
        else
        {
            _logger.LogWarning(
                "Unable to add shape to the zone using the <zone> tag helper because the zone's type is " +
                "\"{ActualType}\" instead of the expected {ExpectedType}",
                zone.GetType().FullName,
                nameof(Shape));

View on GitHub (pinned to 4306c0717f)