William Scheffey avatar image
William Scheffey asked

Basic C# example not working.

Hello, first time user here. I'm trying to test the most basic code sample for C# but it isn't working and it's throwing a very vague exception. Code and exception below. I replaced the sensitive variables with comments describing what they had been set to.

using System;
using System.Threading.Tasks;
using RingCentral;
using DotNetEnv;

namespace Call_Ringout
    class Program
        static RestClient restClient;
        static void Main(string[] args)
            restClient = new RestClient(
                /*Client ID*/,
                /*Client Secret*/,

        static private async Task call_ringout()
            var parameters = new MakeRingOutRequest();
            parameters.from = new MakeRingOutCallerInfoRequestFrom
                phoneNumber = /*From Number*/
   = new MakeRingOutCallerInfoRequestTo
                phoneNumber = /*To Number*/
            parameters.callerId = new MakeRingOutCallerInfoRequestTo
                phoneNumber = /From Number/
   = new MakeRingOutCoutryInfo
                id = "1"
            parameters.playPrompt = false;
            //var resp = await restClient.Restapi().Account().Extension().RingOut().Post(parameters);
            //Console.WriteLine("Call Placed. Call status" + resp.status.callStatus);

            var _1 = restClient.Restapi();
            var _2 = _1.Account();
            var _3 = _2.Extension();
            var _4 = _3.RingOut();
                var resp = await _4.Post(parameters);
                Console.WriteLine("Call Placed. Call status" + resp.status.callStatus);
            catch(Exception e)

I broke up the line

var resp = await restClient.Restapi().Account().Extension().RingOut().Post(parameters);

Into its component parts to see where the problem is. It is in the last part, which is why I put the try block around it alone.

Here is the error I'm getting:

Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
   at RingCentral.RestClient.Request(HttpRequestMessage httpRequestMessage, Int32 retriedTimes, Nullable`1 cancellationToken)
   at RingCentral.RestClient.Request(HttpMethod httpMethod, String endpoint, Object content, Object queryParams, Nullable`1 cancellationToken)
   at RingCentral.RestClient.Request[T](HttpMethod httpMethod, String endpoint, Object content, Object queryParams, Nullable`1 cancellationToken)
   at RingCentral.RestClient.Post[T](String endpoint, Object content, Object queryParams, Nullable`1 cancellationToken)
   at RingCentral.Paths.Restapi.Account.Extension.RingOut.Index.Post(MakeRingOutRequest makeRingOutRequest, Nullable`1 cancellationToken)
   at Call_Ringout.Program.call_ringout() in C:\Users\wscheffey\source\repos\Call_Ringout\Call_Ringout\Program.cs:line 55

C:\Program Files\dotnet\dotnet.exe (process 28572) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .

Any help greatly appreciated.

rest api
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

0 Answers

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys