We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

null reference exception when adding a seccond appointment in SfSchedule

i want to add som reccurring appointments to an SfSchedule Control, it accept the dirst appointment that i put in it, but when i want to add a second one it gives me a null reference exception.

this is my code:

var appointment = ((Horarios.BindingClass) DataContext).Appointment as ScheduleAppointment ??
                              new ScheduleAppointment();

            RecurrenceProperties RecProp = new RecurrenceProperties
            {
                RecurrenceType = RecurrenceType.Weekly,
                IsRangeRecurrenceCount = false,
                IsRangeNoEndDate = true,
                IsRangeEndDate = false,

            };
           
           

            switch (((Horarios.BindingClass)DataContext).CurrentSelectedDate.Value.DayOfWeek)
            {
                case DayOfWeek.Sunday:
                    break;
                case DayOfWeek.Monday:
                    RecProp.IsWeeklyMonday = true;
                    break;
                case DayOfWeek.Tuesday:
                    RecProp.IsWeeklyTuesday = true;
                    break;
                case DayOfWeek.Wednesday:
                    RecProp.IsWeeklyWednesday = true;
                   
                    break;
                case DayOfWeek.Thursday:
                    RecProp.IsWeeklyThursday = true;
                    break;
                case DayOfWeek.Friday:
                    RecProp.IsWeeklyFriday = true;
                    break;
                case DayOfWeek.Saturday:

                    RecProp.IsWeeklySaturday = true;
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            appointment.StartTime = StartTime.DateTime.Value;
            appointment.EndTime = EndTime.DateTime.Value;
            appointment.RecurrenceRule = ScheduleHelper.RRuleGenerator(RecProp,
            appointment.StartTime, appointment.EndTime);
            appointment.IsRecursive = false;
            EditorPage.Schedule.Appointments.Add(appointment);

i always get  a null reference exception on the last line when i'm addin a second appointment, does not matter if it is a recurrent appointment or not.

1 Reply

SP Sivakumar Punniya Moorthi Syncfusion Team August 18, 2017 07:27 PM UTC

Hi Jesus, 

Thanks for using Syncfusion products. 

We had prepared a sample with the provided code snippet. Can you please provide as the following information?  So that we could provide you the prompt solution. 
1.      Version of SfSchedule.WPF.dll 
2.      .Net framework used. 
3.      Screen shot or stack trace of the Exception occurred. 

Sample Link :  ScheduleApp
 

Regards, 
Sivakumar P 


Loader.
Live Chat Icon For mobile
Up arrow icon