"Null Reference Exception" on the method Recalculate()

Hi, I am having the error "Null Reference Exception" on the method Recalculate().

The error occur when I use the duration greater than 80 and the unit of the resource of 0.0223.
In the example above if I use 80 as duration it owrks fine, if I use 81 I get the error.

Best Regards,
Andre Makoski

Here is the example code and the Stack Trace:

private static void CreateFile(string fileName, string saveFileName)
{
Project project = new Project();

project.CalculationMode = CalculationMode.Manual;

Task Task1 = project.RootTask.Children.Add();
SetTaskData(Task1, 1, "001", false, ConstraintType.AsSoonAsPossible);
Task Task2 = Task1.Children.Add();
SetTaskData(Task2, 2, "001.01", true, ConstraintType.StartNoEarlierThan);

Resource rsc1 = project.Resources.Add("Resource 1");
rsc1.Set(Rsc.Code, "ISM");
rsc1.Set(Rsc.Name, "Resource 1");
rsc1.Set(Rsc.Type, ResourceType.Material);

project.ResourceAssignments.Add(Task2, rsc1, 0.0223);

project.Recalculate();
project.Save(saveFileName, Aspose.Tasks.Saving.SaveFileFormat.XML);
}

private static void SetTaskData(Task task, Double duracao, string wbs, bool manual, ConstraintType tipo)
{
task.Set(Tsk.Name, "Tarefa " + duracao.ToString());
task.Set(Tsk.WBS, wbs);
task.Set(Tsk.Cost, 1);
task.Set(Tsk.IsManual, manual);
task.Set(Tsk.Type, TaskType.FixedDuration);
task.Set(Tsk.DurationFormat, TimeUnitType.Day);
task.Set(Tsk.IsCritical, true);
task.Set(Tsk.IsActive, true);
task.Set(Tsk.IsMilestone, false);
task.Set(Tsk.ConstraintType, tipo);

DateTime start = new DateTime(2015, 1, 1);
DateTime finish = new DateTime(2015, 4, 23);
task.Set(Tsk.Start, start);
task.Set(Tsk.Finish, finish);
task.Set(Tsk.Duration, task.ParentProject.GetDuration(81, TimeUnitType.Day));
task.Set(Tsk.EarlyStart, start);
task.Set(Tsk.EarlyFinish, finish);
task.Set(Tsk.LateStart, start);
task.Set(Tsk.LateFinish, finish);
}

StackTrace:

em . (SplitPartCollection )
em . (DateTime , SplitPartCollection )
em . (DateTime )
em Aspose.Tasks.ResourceAssignment. (DateTime )
em Aspose.Tasks.Task. ()
em ​ . ()
em ​ . ​ ()
em Aspose.Tasks.Task. ()
em Aspose.Tasks.Project.Recalculate()
em TesteProject.Form1.CreateFile(String fileName, String saveFileName) na c:\users\andre.makoski\documents\visual studio 2015\Projects\TesteProject\TesteProject\Form1.cs:linha 44
em TesteProject.Form1.button1_Click(Object sender, EventArgs e) na c:\users\andre.makoski\documents\visual studio 2015\Projects\TesteProject\TesteProject\Form1.cs:linha 23
em System.Windows.Forms.Control.OnClick(EventArgs e)
em System.Windows.Forms.Button.OnClick(EventArgs e)
em System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
em System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
em System.Windows.Forms.Control.WndProc(Message& m)
em System.Windows.Forms.ButtonBase.WndProc(Message& m)
em System.Windows.Forms.Button.WndProc(Message& m)
em System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
em System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
em System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
em System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
em System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
em System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
em System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
em System.Windows.Forms.Application.Run(Form mainForm)
em TesteProject.Program.Main() na c:\users\andre.makoski\documents\visual studio 2015\Projects\TesteProject\TesteProject\Program.cs:linha 19
em System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
em System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
em Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
em System.Threading.ThreadHelper.ThreadStart_Context(Object state)
em System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
em System.Threading.ThreadHelper.ThreadStart()

Hi Andre,

Thank you for your interest in Aspose.

Please try removing the below highlighted line of code that sets the task’s IsActive property and see if that resolves your issue. If not, please let us know which version of Aspose.Tasks you are using at your end. We’ll look into it to assist you accordingly.

private static void SetTaskData(Aspose.Tasks.Task task, Double duracao, string wbs, bool manual, ConstraintType tipo)

{

task.Set(Tsk.Name, "Tarefa " + duracao.ToString());

task.Set(Tsk.WBS, wbs);

task.Set(Tsk.Cost, 1);

task.Set(Tsk.IsManual, manual);

task.Set(Tsk.Type, TaskType.FixedDuration);

task.Set(Tsk.DurationFormat, TimeUnitType.Day);

task.Set(Tsk.IsCritical, true);

task.Set(Tsk.IsActive, true);

task.Set(Tsk.IsMilestone, false);

task.Set(Tsk.ConstraintType, tipo);

DateTime start = new DateTime(2015, 1, 1);

DateTime finish = new DateTime(2015, 4, 23);

task.Set(Tsk.Start, start);

task.Set(Tsk.Finish, finish);

task.Set(Tsk.Duration, task.ParentProject.GetDuration(80, TimeUnitType.Day));

task.Set(Tsk.EarlyStart, start);

task.Set(Tsk.EarlyFinish, finish);

task.Set(Tsk.LateStart, start);

task.Set(Tsk.LateFinish, finish);

}

Hi there Maria, thanks for the fast response.

I removed the line you asked and got the same error.
I am using version 16.11.


Regards,
Andre Makoski

Hello.


This is my whole solution attached.
I keep having the Sytem.NullReferenceException when using the duration of 81.

Best regards,
Andre Makoski

Hi Andre,

Thank you for sharing your sample project. We were able to reproduce the same issue as reported by you in the attached project. We have logged the issue as TASKSNET-1769 for further investigation by our product team. We’ll let you know once there is any further progress or a fix version available in this regard.

Hi Andre,


We are sorry to share that there is no ETA available for your issue logged as TASKSNET-1769 for now. We have requested our Product team to share an approximate ETA for the resolution of this problem and will share with you here as soon as it is available.

Hi Andre,


Our product team has worked out this issue and it will be available in the upcoming version of Aspose.Tasks for .NET 17.3.0. We would also like to share with you that the current implementation of CalculationMode.Manual has some issues that will take our Product team considerable time and efforts for complete fix. We recommend you to use CalculationMode.None instead of Manual Mode for correct results.

The issues you have found earlier (filed as TASKSNET-1769) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.