OrchardCMS/OrchardCore · error · ArgumentException
MessageId can't be empty.
Error message
MessageId can't be empty.
What it means
CultureDictionaryRecord.GetKey builds the composite record key from a messageId and optional context, and requires a non-empty messageId. An empty or null messageId would produce a meaningless key, so ArgumentException with the parameter name is thrown as a standard argument guard.
Solutions
- Ensure the messageId passed to GetKey/record construction is non-empty before calling.
- Add a guard in your own code (ArgumentException.ThrowIfNullOrWhiteSpace) with a clearer message.
- Fix the data source producing empty message ids (e.g. skip blank PO entries during import).
Example fix
// before
var key = CultureDictionaryRecord.GetKey(messageId, context);
// after
if (string.IsNullOrWhiteSpace(messageId)) throw new ArgumentException("Message id required", nameof(messageId));
var key = CultureDictionaryRecord.GetKey(messageId, context); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(messageId)) return null; // or throw with context var key = CultureDictionaryRecord.GetKey(messageId, context);
Try / catch
try { key = CultureDictionaryRecord.GetKey(messageId, ctx); }
catch (ArgumentException) { logger.LogWarning("Empty messageId for context '{Context}'; skipping", ctx); } Prevention
- Skip empty strings before calling localization APIs
- Sanitize PO import pipelines to drop blank entries
When it happens
Trigger: Calling GetKey (or the CultureDictionaryRecord constructor that delegates to it) with null, empty, or whitespace messageId — e.g. localizing a string variable that is empty at runtime.
Common situations: Building localization records from parsed PO entries where an entry is malformed, or passing user/editor-supplied text that ends up empty into translation lookup helpers.
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
- PluralForms array can't be empty, it must contain at least…
- PluralForms array can't be empty, it must contain at least…
- The calendar is not supported.
- File path must be a non-empty string.
- Parameters must have the same length
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/c78c78f7844f0cd9.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.Localization.Abstractions/CultureDictionaryRecord.cs:51
/// </summary>
public CultureDictionaryRecordKey Key { get; }
/// <summary>
/// Gets the translation values.
/// </summary>
public string[] Translations { get; }
/// <summary>
/// Retrieved the resource key using <paramref name="messageId"/> and <paramref name="context"/>.
/// </summary>
/// <param name="messageId">The message Id.</param>
/// <param name="context">The message context.</param>
/// <returns>The resource key.</returns>
public static CultureDictionaryRecordKey GetKey(string messageId, string context)
{
if (string.IsNullOrEmpty(messageId))
{
throw new ArgumentException("MessageId can't be empty.", nameof(messageId));
}
return new CultureDictionaryRecordKey
{
MessageId = messageId,
Context = context,
};
}
}
View on GitHub (pinned to 4306c0717f)