Domanda

I am trying to send a SMS using twilio but when i use the code i get the following errors:

Error 1

Error 11 The call is ambiguous between the following methods or properties: 'Twilio.TwilioRestClient.SendMessage(string, string, string, string[], string)' and 'Twilio.TwilioRestClient.SendMessage(string, string, string, string[], System.Action)'
C:\Development\TestSMSVerify.aspx.cs

Error 2

Cannot assign void to an implicitly-typed local variable

Does anyone know how i can fix this?

The code is

// Find your Account Sid and Auth Token at twilio.com/user/account 
string AccountSid = "MYSID";
string AuthToken = "MYAUTHTOKEN";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var message = twilio.SendMessage("+441618504425", "07914164512", "code is 123456", null, null);
Console.WriteLine(message.Sid); 
È stato utile?

Soluzione

The problem is SendMessage has 2 overloads, one which takes a string type as the last parameter and one that takes an Action<Twilio.Message>. You are passing null for this which is acceptable for both of these types, however, confuses the compiler because it can't quite work out which method you want it to call.

For example, if you passed an empty string as the last parameter e.g.

 twilio.SendMessage("+441618504425", "07914164512", "code is 123456", null, "");

Then the compiler would know that you want the overload with the string parameter at the end, not the one with an Action<Twilio.Message>. Alternatively, if you passed an empty Action<Twilio.Message> parameter e.g.

 twilio.SendMessage("+441618504425", "07914164512", "code is 123456", null, (msg) => {});

Then it would know that you want the call which takes an Action<Twilio.Message> parameter and not a string.

Finally, I believe this error

Cannot assign void to an implicitly-typed local variable

Is because SendMessage doesn't actually return anything. To fix, just change

var message = twilio.SendMessage(...);

To

twilio.SendMessage(...);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top