A: 

It appears that your Calendar.DayView control calls the OnResolveAppointments function within its override of OnPaint. I would suggest you examine the code there.

In the meantime, you could probably just skip over the For Each if appointments is Nothing.

Adam Robinson
A: 

DayView1_ResolveAppointments is clearly an event handler for the ResolveAppointments event of the DayView1 control. If the For Each is throwing the exception, then it means that appointments is Nothing at that time, and not an empty list, as you expect it to be. Add

If appointments Is Nothing Then
    Return
End If

before the For Each loop.

John Saunders
A: 

That solved the NullReferenceException error, but now I get another error when I call the ResolveAppointments method.

DayView1.ResolveAppointments()

Error 1 'Public Event ResolveAppointments(sender As Object, args As Calendar.ResolveAppointmentsEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event. C:\Users\Daniel\My Programs\Visual Basic\SeaCow\SeaCow\SeaCow\Main.vb 224 9 SeaCow

Here is the ResolveAppointments function from the DayView.cs file.

        protected virtual void ResolveAppointments(ResolveAppointmentsEventArgs args)
    {
        System.Diagnostics.Debug.WriteLine("Resolve app");

        if (OnResolveAppointments != null)
            OnResolveAppointments(this, args);

        this.allDayEventsHeaderHeight = 0;

        // cache resolved appointments in hashtable by days.
        cachedAppointments.Clear();

        if ((selectedAppointmentIsNew) && (selectedAppointment != null))
        {
            if ((selectedAppointment.StartDate > args.StartDate) && (selectedAppointment.StartDate < args.EndDate))
            {
                args.Appointments.Add(selectedAppointment);
            }
        }

        foreach (Appointment appointment in args.Appointments)
        {
            int key = -1;
            AppointmentList list;

            if (appointment.StartDate.Day == appointment.EndDate.Day && appointment.AllDayEvent == false)
            {
                key = appointment.StartDate.Day;
            }
            else
            {
                key = -1;
            }

            list = (AppointmentList)cachedAppointments[key];

            if (list == null)
            {
                list = new AppointmentList();
                cachedAppointments[key] = list;
            }

            list.Add(appointment);
        }
    }
Daniel