OrchardCMS/OrchardCore · error · ArgumentException
The 'displayName' can't be null or empty.
Error message
The 'displayName' can't be null or empty.
What it means
ContentDefinitionService.AddTypeAsync creates a new content type and requires a non-empty display name, since the display name drives the admin UI label and (when no name is supplied) the generated technical name. It throws ArgumentException with the parameter name when displayName is null, empty, or whitespace.
Solutions
- Supply a meaningful displayName before calling AddTypeAsync.
- Validate with string.IsNullOrWhiteSpace on the caller side and show a form validation error instead.
- If only a technical name is known, derive a display name from it before invoking the service.
Example fix
// before
await _contentDefinitionService.AddTypeAsync("Product", "");
// after
if (string.IsNullOrWhiteSpace(displayName)) throw new ValidationException("Display name is required");
await _contentDefinitionService.AddTypeAsync("Product", displayName); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(displayName))
throw new ArgumentException("Display name is required.", nameof(displayName)); Type guard
static bool IsValidDisplayName(string? s) => !string.IsNullOrWhiteSpace(s);
Try / catch
try { await _service.AddTypeAsync(name, displayName); }
catch (ArgumentException ex) when (ex.ParamName == nameof(displayName))
{
ModelState.AddModelError(nameof(displayName), "Display name is required.");
return View(model);
} Prevention
- Mark the display-name field [Required] in admin forms
- Always validate user input before service calls
- Never pass unset variables as displayName
- Derive display names from identifiers when only a name is known
When it happens
Trigger: Calling AddTypeAsync(name, displayName) with null/empty/whitespace displayName — e.g. an admin 'Create new type' form submitted blank, or custom code passing an unset variable.
Common situations: Custom type-creation tooling or scripts that skip UI validation; automated provisioning code building types from user input without checking the display name.
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
- Content type name must start with a letter
- Content type name contains invalid characters
- File path must be a non-empty string.
- Parameters must have the same length
- The values for and must not be the same.
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/8bc5ca2784e6ae93.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/ContentDefinitionService.cs:53
foreach (var element in contentParts.Select(x => x.GetType()))
{
logger.LogError("The content part '{ContentPart}' should not be registered in DI. Use AddContentPart<T>() instead.", element);
}
foreach (var element in contentFields.Select(x => x.GetType()))
{
logger.LogError("The content field '{ContentField}' should not be registered in DI. Use AddContentField<T>() instead.", element);
}
_logger = logger;
S = stringLocalizer;
}
public async Task<ContentTypeDefinition> AddTypeAsync(string name, string displayName)
{
if (string.IsNullOrWhiteSpace(displayName))
{
throw new ArgumentException($"The '{nameof(displayName)}' can't be null or empty.", nameof(displayName));
}
if (string.IsNullOrWhiteSpace(name))
{
name = await GenerateContentTypeNameFromDisplayNameAsync(displayName);
}
else
{
if (!char.IsAsciiLetter(name[0]))
{
throw new ArgumentException("Content type name must start with a letter", nameof(name));
}
if (!string.Equals(name, name.ToSafeName(), StringComparison.OrdinalIgnoreCase))
{
throw new ArgumentException("Content type name contains invalid characters", nameof(name));
}
}
View on GitHub (pinned to 4306c0717f)