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

Object reference exception when drag and drop task


I get an object reference exception when I try to drag a task in the Gantt control to change the duration.

I am using the following class


public class PlannedTask : IPlannedTask


    private IWorkPlace _assignWorkPlace;

    public PlannedTask()


        PredecessorList = new List<IPlannedTask>();

        SuccessorList = new List<IPlannedTask>();

        RelatedWorkPlaces = new List<IWorkPlace>();


    public string Id { get; set; }

    public string Oid { get; set; }

    public PlannedTaskType Type { get; set; }

    public string Name => $"{Id}";

    public string Description { get; set; }

    public string ParentOid { get; set; }

    public DateTime? StartDate { get; set; }

    public string DurationInMinutesStr { get; set; }

    public int DurationInMinutes { get; set; }

    public string DurationUnit {get;set; }

    public DateTime? EndDate { get; set; }

    public DateTime? EndDateByDuration




            if (StartDate != null)


                switch (DurationUnit)


                    case "minute": return StartDate.Value.AddMinutes(DurationInMinutes);

                    //case "hour": return StartDate.Value.AddHours(Duration);

                    //case "day": return StartDate.Value.AddDays(Duration);



            return null;



    public int Progress { get; set; }

    public bool IsScheduled { get; set; }

    public IList<IWorkPlace> RelatedWorkPlaces { get; set; }

    public IWorkPlace AssignedWorkPlace => _assignWorkPlace;

    public IPlannedTask ParentTask { get; set; }

    public string Predecessors => string.Join(",", PredecessorList.Select(x => x.Oid));

    public string Successors => string.Join(",", SuccessorList.Select(x => x.Oid));

    public IList<IPlannedTask> PredecessorList { get; set; }

    public IList<IPlannedTask> SuccessorList { get; set; }

    public void AssignWorkPlace(IWorkPlace workPlace)


        _assignWorkPlace = workPlace;

        var task = workPlace.AssignedTasks.FirstOrDefault(x => x.Id == this.Id);

        if (task == null)





    public override string ToString()


        return $"{Type} {(IsScheduled ? "(s)" : "(p)")} {Oid} - Start: {StartDate}, End: {EndDate} Duration {DurationInMinutes} min. Predecessors {Predecessors} Successors {Successors} ";



And I have the following exception

System.NullReferenceException: Object reference not set to an instance of an object.

   at Syncfusion.Blazor.Data.BlazorAdaptor.BatchUpdate(DataManager dataManager, Object changed, Object added, Object deleted, Utils e, String keyField, Nullable`1 dropIndex, Query query, Object original)

   at Syncfusion.Blazor.DataManager.SaveChanges[T](Object changed, Object added, Object deleted, String keyField, Nullable`1 dropIndex, String tableName, Query query, Object Original)

   at Syncfusion.Blazor.Gantt.Internal.EditBase`1.InitiateUpdateAction(EditedArgs args)

   at Syncfusion.Blazor.Gantt.Internal.EditBase`1.UpdateEditedRecords(EditedArgs args, GanttTaskModel GanttProperties)

   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)

   at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.ExecuteSynchronously(TaskCompletionSource`1 completion, SendOrPostCallback d, Object state)

   at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.<>c.<.cctor>b__23_0(Object state)

   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

--- End of stack trace from previous location ---

   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

   at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.ExecuteBackground(WorkItem item)

3 Replies

AG Ajithkumar Gopalakrishnan Syncfusion Team April 27, 2023 11:42 AM UTC

Hi Arjan,

Thanks for contacting syncfusion forum.

Before proceeding this, we would like to investigate this further to better understand the root cause. Could you please provide us with additional information to find the exact cause of the issue. Share us the following details.

  1. Complete Gantt code details.(Gantt rendering code)
  2. Screenshot/Video demo to replicate the issue.
  3. Replication steps to replicate the problem.
  4. NuGet package version details.

Once we receive this information, we will proceed with further investigation and provide you with an update as soon as possible.


Ajithkumar G

AR Arjan April 30, 2023 06:00 PM UTC


I have added a sample solution.

Steps to reproduce:

  1. Compile and start solution in VS
  2. Try to drag the duration of a task
  3. An exception occured

Attachment: BlazorApp1_283512ba.zip

RB Rajesh Babu Syncfusion Team May 2, 2023 12:29 PM UTC

Hi Arjan,

We are able to replicate the problem from the shared sample. Further analysis, the primary key field has not been defined in a column definition. To overcome this, we suggest defining the primary column in GanttColumns to enable editing.

<SfGantt DataSource="@TaskCollection" Height="450px" Width="700px" HighlightWeekends="true">

    <GanttTaskFields Id="Oid" Name="Name" StartDate="StartDate" EndDate="EndDate"

                     Duration="DurationInMinutesStr" DurationUnit="DurationUnit" Progress="Progress" ParentID="ParentOid" Dependency="Predecessors">



        <GanttColumn Field="Oid"></GanttColumn>

        <GanttColumn Field="Name" HeaderText="Task Name" Width="250"></GanttColumn>

        <GanttColumn Field="StartDate" HeaderText="Start Date" Width="250"></GanttColumn>

        <GanttColumn Field="DurationInMinutesStr" Format="" HeaderText="Duration" Width="250"></GanttColumn>


    <GanttEditSettings AllowTaskbarEditing="true"></GanttEditSettings>

    <GanttTimelineSettings TimelineViewMode="TimelineViewMode.Week"></GanttTimelineSettings>


Refer to the provided link:  https://blazor.syncfusion.com/documentation/gantt-chart/managing-tasks#troubleshoot-editing-works-only-when-primary-key-column-is-defined   

Best Regards,

Rajesh BS

Live Chat Icon For mobile
Up arrow icon