OrchardCMS/OrchardCore · error · ArgumentException
A phone number is required in order to send a message.
Error message
A phone number is required in order to send a message.
What it means
TwilioSmsProvider.SendAsync validates the SmsMessage before calling the Twilio API and throws ArgumentException when message.To (the recipient phone number) is null or empty. Without a destination the provider cannot send, so it fails fast instead of making a doomed HTTP call.
Solutions
- Set SmsMessage.To to a valid E.164 phone number (e.g. "+14155552671") before calling SendAsync.
- If the number comes from user content, validate it is non-empty before invoking the provider and surface a friendly validation message instead.
- Catch ArgumentException around SendAsync if the number is optional and treat it as a skipped send.
- Verify any workflow/activity bindings actually map the phone number into message.To.
Example fix
// before
await provider.SendAsync(new SmsMessage { Body = "Hello" });
// after
await provider.SendAsync(new SmsMessage { To = "+14155552671", Body = "Hello" }); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(message?.To))
return Result.Failed(new ErrorResult { Key = "RecipientRequired", ErrorMessage = "A phone number is required." }); Type guard
static bool CanSend(SmsMessage m) => m is not null && !string.IsNullOrWhiteSpace(m.To) && !string.IsNullOrWhiteSpace(m.Body);
Try / catch
try
{
await provider.SendAsync(message, ct);
}
catch (ArgumentException ex)
{
logger.LogWarning(ex, "SMS skipped: {Message}", ex.Message);
} Prevention
- Validate phone numbers at input time (E.164 format) before storing.
- Check workflow bindings for the To field resolve to a non-empty value.
- Treat missing recipient as a user-facing validation error, not a send failure.
- Add a null/empty guard in any wrapper service around SmsMessage construction.
When it happens
Trigger: Calling SendAsync with an SmsMessage whose To property is null or an empty string, e.g. built from a workflow Sms activity or form where the phone field was never populated.
Common situations: User-submitted phone number field left blank; workflow property binding to a nonexistent content field; tenant SMS settings collected a default sender but the recipient comes from dynamic content that is missing.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- A message body is required in order to send a message.
- A virtual path is required
- Both the index-name and index full-name must be set.
- Cannot add model validation errors when there's no Updater…
- Cannot add model validation errors when there's no Updater…
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/c98b9d9a0db6d6d3.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.Sms.Core/Services/TwilioSmsProvider.cs:56
_options = options;
_logger = logger;
_httpClientFactory = httpClientFactory;
S = stringLocalizer;
}
/// <summary>
/// Sends the specified SMS message by using the configured Twilio account.
/// </summary>
/// <param name="message">The SMS message to send.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A <see cref="Result"/> describing whether Twilio accepted the SMS message.</returns>
public async Task<Result> SendAsync(SmsMessage message, CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(message);
if (string.IsNullOrEmpty(message.To))
{
throw new ArgumentException("A phone number is required in order to send a message.");
}
if (string.IsNullOrEmpty(message.Body))
{
throw new ArgumentException("A message body is required in order to send a message.");
}
try
{
var settings = _options.CurrentValue;
var senderNumber = settings.PhoneNumber;
if (!string.IsNullOrEmpty(message.From))
{
senderNumber = message.From;
}
View on GitHub (pinned to 4306c0717f)