{"record":{"id":"a79e9b18742fff75","repo":"nopSolutions/nopCommerce","slug":"template-cannot-be-loaded","errorCode":null,"errorMessage":"Template cannot be loaded","messagePattern":"Template cannot be loaded","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Libraries/Nop.Services/Messages/WorkflowMessageService.cs","lineNumber":2670,"sourceCode":"                replyToEmailAddress: senderEmail,\r\n                replyToName: senderName);\r\n        }).ToListAsync();\r\n    }\r\n\r\n    /// <summary>\r\n    /// Sends a test email\r\n    /// </summary>\r\n    /// <param name=\"messageTemplateId\">Message template identifier</param>\r\n    /// <param name=\"sendToEmail\">Send to email</param>\r\n    /// <param name=\"tokens\">Tokens</param>\r\n    /// <param name=\"languageId\">Message language identifier</param>\r\n    /// <returns>\r\n    /// A task that represents the asynchronous operation\r\n    /// The task result contains the queued email identifier\r\n    /// </returns>\r\n    public virtual async Task<int> SendTestEmailAsync(int messageTemplateId, string sendToEmail, List<Token> tokens, int languageId)\r\n    {\r\n        var messageTemplate = await _messageTemplateService.GetMessageTemplateByIdAsync(messageTemplateId) ?? throw new ArgumentException(\"Template cannot be loaded\");\r\n\r\n        //email account\r\n        var emailAccount = await GetEmailAccountOfMessageTemplateAsync(messageTemplate, languageId);\r\n\r\n        //event notification\r\n        await _eventPublisher.MessageTokensAddedAsync(messageTemplate, tokens);\r\n\r\n        return await SendNotificationAsync(messageTemplate, emailAccount, languageId, tokens, sendToEmail, null, ignoreDelayBeforeSend: true);\r\n    }\r\n\r\n    #endregion\r\n\r\n    #region Common\r\n\r\n    /// <summary>\r\n    /// Get active message templates by the name\r\n    /// </summary>\r\n    /// <param name=\"messageTemplateName\">Message template name</param>\r","sourceCodeStart":2652,"sourceCodeEnd":2688,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Services/Messages/WorkflowMessageService.cs#L2652-L2688","documentation":"Thrown by WorkflowMessageService.SendTestEmailAsync when _messageTemplateService.GetMessageTemplateByIdAsync(messageTemplateId) returns null. Unlike the order errors this is an ArgumentException (input contract violation) - the caller passed a template id that resolves to no template. Used by the admin 'Send test email' action on the message template editor.","triggerScenarios":"Admin clicks 'Send test email' for a template id that was deleted, never existed, or belongs to another store scope. Passing 0 or a stale id from a URL bookmark after the template was removed.","commonSituations":"Stale admin bookmark to a deleted template; race between two admins where one deletes the template while the other sends a test; import that failed to bring the template row; wrong messageTemplateId wired into a custom controller.","solutions":["Refresh the admin message-template list and reselect the template before sending the test email.","If the template is genuinely gone, recreate it or restore from a backup/export.","In custom code calling SendTestEmailAsync, validate the id resolves before invoking."],"exampleFix":"// before\nawait _workflowMessageService.SendTestEmailAsync(templateId, email, tokens, languageId);\n\n// after\nvar template = await _messageTemplateService.GetMessageTemplateByIdAsync(templateId);\nif (template is null)\n    return NotFound($\"Message template {templateId} not found.\");\nawait _workflowMessageService.SendTestEmailAsync(templateId, email, tokens, languageId);","handlingStrategy":"validation","validationCode":"var template = await _messageTemplateService.GetMessageTemplateByIdAsync(messageTemplateId);\nif (template is null)\n    return NotFound($\"Message template {messageTemplateId} does not exist.\");\n\nawait _workflowMessageService.SendTestEmailAsync(messageTemplateId, sendToEmail, tokens, languageId);","typeGuard":"async Task<bool> TemplateExistsAsync(int id)\n    => id > 0 && await _messageTemplateService.GetMessageTemplateByIdAsync(id) is not null;","tryCatchPattern":"try\n{\n    await _workflowMessageService.SendTestEmailAsync(messageTemplateId, email, tokens, languageId);\n}\ncatch (ArgumentException ex) when (ex.Message == \"Template cannot be loaded\")\n{\n    return NotFound(\"Message template was deleted or does not exist. Refresh the list and retry.\");\n}","preventionTips":["Resolve the template id to an entity before calling SendTestEmailAsync.","Refresh admin views after deleting templates so stale ids are not reused.","Validate messageTemplateId > 0 and exists in the current store scope before the test-email action."],"tags":["email","message-template","admin","argument","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}