{"record":{"id":"c78c78f7844f0cd9","repo":"OrchardCMS/OrchardCore","slug":"messageid-can-t-be-empty","errorCode":null,"errorMessage":"MessageId can't be empty.","messagePattern":"MessageId can't be empty\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Localization.Abstractions/CultureDictionaryRecord.cs","lineNumber":51,"sourceCode":"    /// </summary>\n    public CultureDictionaryRecordKey Key { get; }\n\n    /// <summary>\n    /// Gets the translation values.\n    /// </summary>\n    public string[] Translations { get; }\n\n    /// <summary>\n    /// Retrieved the resource key using <paramref name=\"messageId\"/> and <paramref name=\"context\"/>.\n    /// </summary>\n    /// <param name=\"messageId\">The message Id.</param>\n    /// <param name=\"context\">The message context.</param>\n    /// <returns>The resource key.</returns>\n    public static CultureDictionaryRecordKey GetKey(string messageId, string context)\n    {\n        if (string.IsNullOrEmpty(messageId))\n        {\n            throw new ArgumentException(\"MessageId can't be empty.\", nameof(messageId));\n        }\n\n        return new CultureDictionaryRecordKey\n        {\n            MessageId = messageId,\n            Context = context,\n        };\n    }\n}\n","sourceCodeStart":33,"sourceCodeEnd":61,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Localization.Abstractions/CultureDictionaryRecord.cs#L33-L61","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nvar key = CultureDictionaryRecord.GetKey(messageId, context);\n// after\nif (string.IsNullOrWhiteSpace(messageId)) throw new ArgumentException(\"Message id required\", nameof(messageId));\nvar key = CultureDictionaryRecord.GetKey(messageId, context);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(messageId)) return null; // or throw with context\nvar key = CultureDictionaryRecord.GetKey(messageId, context);","typeGuard":null,"tryCatchPattern":"try { key = CultureDictionaryRecord.GetKey(messageId, ctx); }\ncatch (ArgumentException) { logger.LogWarning(\"Empty messageId for context '{Context}'; skipping\", ctx); }","preventionTips":["Skip empty strings before calling localization APIs","Sanitize PO import pipelines to drop blank entries"],"tags":["localization","argument-validation"],"backgroundTag":"empty-required-field","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"}