Question

CS0103 exception when trying to send SMS

  • 7 January 2021
  • 11 replies
  • 1118 views

Trying this code to send SMS in C# it is throwing a CS0103 at this point:

var response = await extension.Sms().Post(requestBody); //name extension does not exist in current context.


The full code
public async void sendSms()
{
RestClient rc;
rc = new RestClient("id, "clientsecret", "https://platform.devtest.ringcentral.com");
var requestBody = new
{
text = "Test",
from = new { textFrom = "+15551212" },
to = new object[] { new { sendTo = "+15551231" } }
};
var response = await extension.Sms().Post(requestBody); //Can't get past this point.
}






11 replies

Userlevel 1

Check out this quick start sample code to use the SDK for sending SMS messages.

https://developers.ringcentral.com/guide/messaging/quick-start#c#

Thanks, There seems to be a problem in

static private async Task read_extension_phone_number()

here
foreach (var record in resp.records) //This throws CS1061
//CompanyPhoneNumberInfo does not contain a definition for 'records'

there are also some other problems with the record variable

I am usinh 3136362490

Userlevel 1

I don't know why the phone-number endpoint return null from your account. It should at least return the main company number. But looking into your sandbox account, I see you don't have any other number added to the user "101".

screen-shot-2021-01-08-at-65207-am.png

You can login your sandbox service web, browse to the page as shown above, then click the Add Direct Number and follow the instructions to add a number to the user extension.

Test it again.

Neither do I, That is not where I am getting the info from, I am using this. And there is no provision for adding a direct number?? I tried this with Python and it it worked fine...has something changed?
1610118486539.png

Userlevel 1

The site you visit is the RingCentral Developer portal. It is different than the sandbox account admin portal. To setup and config your sandbox such as adding new users, adding new numbers ect. you need to login https://service.devtest.ringcentral.com with your sandbox user's login credentials (not the login credentials for the dev portal!). Alternatively, you can click the "Sandbox Accounts" option from the view you showed above and click on the up-arrow which will log you in the sandbox admin portal.

I will investigate the C# later.

Userlevel 1

After the code below, can you print the "resp" object as string and post it here.

var resp = await restClient.Restapi().Account().Extension().PhoneNumber().Get();

Same result; CS1061 CompanyPhoneNumberInfo does not contain a definition for records

Userlevel 1

Comment out the foreach lines! Just print the response which will not have anything to do with the CompanyPhoneNumberInfo object.

Nothing, It freezes. No exceptions nothing.

Userlevel 1

Once you could try Python code, can you use this Python code?

https://developers.ringcentral.com/guide/messaging/quick-start#python

Reply