{"record":{"id":"e71c024950965caf","repo":"OrchardCMS/OrchardCore","slug":"a-message-body-is-required-in-order-to-send-a-message","errorCode":null,"errorMessage":"A message body is required in order to send a message.","messagePattern":"A message body is required in order to send a message\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Sms.Core/Services/TwilioSmsProvider.cs","lineNumber":61,"sourceCode":"\n    /// <summary>\n    /// Sends the specified SMS message by using the configured Twilio account.\n    /// </summary>\n    /// <param name=\"message\">The SMS message to send.</param>\n    /// <param name=\"cancellationToken\">The cancellation token.</param>\n    /// <returns>A <see cref=\"Result\"/> describing whether Twilio accepted the SMS message.</returns>\n    public async Task<Result> SendAsync(SmsMessage message, CancellationToken cancellationToken = default)\n    {\n        ArgumentNullException.ThrowIfNull(message);\n\n        if (string.IsNullOrEmpty(message.To))\n        {\n            throw new ArgumentException(\"A phone number is required in order to send a message.\");\n        }\n\n        if (string.IsNullOrEmpty(message.Body))\n        {\n            throw new ArgumentException(\"A message body is required in order to send a message.\");\n        }\n\n        try\n        {\n            var settings = _options.CurrentValue;\n\n            var senderNumber = settings.PhoneNumber;\n\n            if (!string.IsNullOrEmpty(message.From))\n            {\n                senderNumber = message.From;\n            }\n\n            var data = new List<KeyValuePair<string, string>>\n            {\n                new (\"From\", senderNumber),\n                new (\"To\", message.To),\n                new (\"Body\", message.Body),","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Sms.Core/Services/TwilioSmsProvider.cs#L43-L79","documentation":"TwilioSmsProvider.SendAsync validates the SmsMessage and throws ArgumentException when message.Body is null or empty. The Twilio API requires message text (or media), so the provider rejects empty bodies before making the HTTP request.","triggerScenarios":"Calling SendAsync with an SmsMessage whose Body property is null or an empty string — e.g. a template rendered to nothing, an empty workflow property, or a message constructed with only a recipient.","commonSituations":"Liquid/templated SMS body evaluated to empty because the content item lacked fields; workflow Sms task configured without a body; localization returning an empty string for the message key.","solutions":["Populate SmsMessage.Body with the message text before calling SendAsync.","If the body is generated from a template, check the rendered result is non-empty before sending and log/validate otherwise.","Catch ArgumentException around SendAsync when empty messages should be silently skipped.","Check the workflow activity or calling code that assembles the SmsMessage actually assigns Body."],"exampleFix":"// before\nawait provider.SendAsync(new SmsMessage { To = \"+14155552671\" });\n// after\nawait provider.SendAsync(new SmsMessage { To = \"+14155552671\", Body = \"Your verification code is 1234\" });","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(message?.Body))\n    return Result.Failed(new ErrorResult { Key = \"BodyRequired\", ErrorMessage = \"A message body is required.\" });","typeGuard":"static bool HasBody(SmsMessage m) => !string.IsNullOrWhiteSpace(m?.Body);","tryCatchPattern":"try\n{\n    await provider.SendAsync(message, ct);\n}\ncatch (ArgumentException ex)\n{\n    logger.LogWarning(ex, \"SMS skipped: {Message}\", ex.Message);\n}","preventionTips":["Check rendered template output for emptiness before sending.","Provide default body text in workflow Sms activities.","Guard against localization keys resolving to empty strings.","Validate both To and Body together in one pre-send check."],"tags":["sms","twilio","validation","empty-body"],"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-23T08:17:48.524Z"}