NullReferenceException on AddOptions(collection)

I’m getting a NullReferenceException when adding a collection of items to a Timeline using AddOptions(collection). Any thoughts on what the problem may be? All the items in the collection have values and each item has a key and label. I’m using the CarRental MVC5 sample code.

DHTMLX Runtime Version: v4.0.30319


Apologies, the correct controller version is: 3.1.5420.31967

Hi,
can you please attach a minimal project where i could reproduce the problem?

I’ve just downloaded the CarRent it MVC5 sample, updated NuGet package of the scheduler and ran the app - the error seems didn’t seem to happen there

I created a simple project by creating an ASP.NET web project using MVC with two models for department and room. I installed dhtmlx scheduler via nuget and added some sample code to populate the models and create a time line view with tree rendermode. I get a nullreferenceexception on the AddOptions() method call.

Please see the attached file which contains a controller with two models, department and rooms. I tried adding the entire project but even that size was too large to upload here. Please let me know if this is suitable.
HomeController.zip (1.38 KB)

Hello,
I’ve reproduced the problem, thanks for the demo.

Looks like the error occurs when you combine TimelineUnit and a custom classes. Null reference exception is fired when the custom class do not have ‘open’ (bool) property defined

The simple way to resolve the problem is to convert Rooms to TimelineUnits before loading them to tree:

foreach (var department in departments) { var section = new TimelineUnit(department.Id, department.Title);// defines the header of the folder timeline.AddOption(section); section.AddOptions(department.Rooms.Select(r => new TimelineUnit(r.Id, r.label))); }

Or to add a ‘open’ property to the Room class (property can have the default value, i.e. no need to initialize it in any way)

public class Room { public int Id { get; set; } public int key { get; set; } public string label { get; set; } public bool open { get; set; } }
The bug will be fixed in the next build, the release is planned on next Wednesday

Thanks for your work around and fix schedule. Funnily enough, the other workaround I came up with was to iterate through each room and add that as a new TimelineUnit:

foreach (var room in department.Rooms)
{
section.AddOption(new TimelineUnit(room.key, room.label));
}