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

  1. Set SmsMessage.To to a valid E.164 phone number (e.g. "+14155552671") before calling SendAsync.
  2. If the number comes from user content, validate it is non-empty before invoking the provider and surface a friendly validation message instead.
  3. Catch ArgumentException around SendAsync if the number is optional and treat it as a skipped send.
  4. 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

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


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)