I am attempting to retrieve a list of Google Calendar Events via the .NET v3 Calendar API.
The following code seems correct, but fails when I call request.Execute(); with the error "object reference not set to an instance of an object" shown here. I don't know how to debug the source of the error, or what "object" isn't being set.
        ServiceAccountCredential credentialService;
        CalendarService service;
        var certificate = new X509Certificate2("filename.p12", "notasecret", X509KeyStorageFlags.Exportable);
        credentialService = new ServiceAccountCredential(
            new ServiceAccountCredential.Initializer("name@here.iam.gserviceaccount.com")
            {
                Scopes = scopes
            }.FromCertificate(certificate));
        // Create the service.
        service = new CalendarService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credentialService,
            ApplicationName = "app name",
        });
        try
        {
            // Define parameters of request.
            EventsResource.ListRequest request = service.Events.List("primary");
            request.TimeMin = DateTime.Now;
            request.ShowDeleted = false;
            request.SingleEvents = true;
            request.MaxResults = 20;
            request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;
            **Events events = request.Execute();**
            if (events.Items != null && events.Items.Count > 0)
            {
                foreach (var eventItem in events.Items)
                {
                    string when = eventItem.Start.DateTime.ToString();
                    if (String.IsNullOrEmpty(when))
                    {
                        when = eventItem.Start.Date;
                    }
                    Item item = new Item();
                    item.Id = Guid.NewGuid().ToString();
                    item.Text = when;
                    item.Description = eventItem.Summary;
                    itemsMeetings.Add(item);
                    //Console.WriteLine("{0} ({1})", eventItem.Summary, when);
                }
            }
            else
            {
                //Console.WriteLine("No upcoming events found.");
            }
        }
        catch(Exception ex)
        {
            Console.Write(ex.Message);
        }
 
    