{"record":{"id":"c98b9d9a0db6d6d3","repo":"OrchardCMS/OrchardCore","slug":"a-phone-number-is-required-in-order-to-send-a-message","errorCode":null,"errorMessage":"A phone number is required in order to send a message.","messagePattern":"A phone number 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":56,"sourceCode":"        _options = options;\n        _logger = logger;\n        _httpClientFactory = httpClientFactory;\n        S = stringLocalizer;\n    }\n\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","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Sms.Core/Services/TwilioSmsProvider.cs#L38-L74","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nawait provider.SendAsync(new SmsMessage { Body = \"Hello\" });\n// after\nawait provider.SendAsync(new SmsMessage { To = \"+14155552671\", Body = \"Hello\" });","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(message?.To))\n    return Result.Failed(new ErrorResult { Key = \"RecipientRequired\", ErrorMessage = \"A phone number is required.\" });","typeGuard":"static bool CanSend(SmsMessage m) => m is not null && !string.IsNullOrWhiteSpace(m.To) && !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":["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."],"tags":["sms","twilio","validation","phone-number"],"backgroundTag":"missing-required-argument","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"}