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
- Add a non-empty Name attribute: <zone Name="Content" />
- If the name is dynamic, validate it is non-empty before rendering the zone tag
- Check attribute casing — the tag helper property is Name
- 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
- Always include a literal or validated Name attribute on <zone> elements
- Null-check dynamic zone names before emitting the tag
- Keep attribute casing as Name for the tag helper binding
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
- Zone not found:
- The 'Default' tenant can't be removed.
- ,
- Content part name must start with a letter
- Content part name contains invalid characters
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)