Hi,
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
{
get
{
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)
{
workPlace.AssignedTasks.Add(this);
}
}
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)
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.
Once we receive this
information, we will proceed with further investigation and provide you with an
update as soon as possible.
Regards,
Ajithkumar G
Hi,
I have added a sample solution.
Steps to reproduce:
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">
</GanttTaskFields>
<GanttColumns>
<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>
</GanttColumns>
<GanttEditSettings AllowTaskbarEditing="true"></GanttEditSettings>
<GanttTimelineSettings TimelineViewMode="TimelineViewMode.Week"></GanttTimelineSettings>
</SfGantt>
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