Different result in in saved MPP on setting CalculationMode (C# .NET)

Hello Aspose,

This ticket is related with Speed Issues
I am using Aspose Tasks for .NET 19.9 with purchased licence.
I am trying to export data into mpp file.

Scenario 1
Setting CalculationMode.Manual or Automatic => Filling Task object => saving.
The result file looks OK, but the export is very slow.

Scenario 2
Setting CalculationMode.None => Filling Task object => Setting CalculationMode.Manual or Automatic => project.Recalculate() => saving.
Export is much faster, but the end dates are shifted.

How to achieve faster export with unchanged date values?

Thank you for your time.

@novotny,

Can you please share source file along with sample code so that we may further investigate to help you out.

While I was creating sample of code for you, I realized where the problem was. I had my input data corrupted (Two independent projects were mixed together in SQL server).
Sorry for my fault.

Off topic…
Anyway. Now the start and finish dates look correct. That’s good. But duration is wrongly calculated.
I never realized it before.
Here is my code.

        string destinationPath = @"C:\Users\some.user\Desktop\AsposeTasksTest.mpp";
        Aspose.Tasks.License l = new Aspose.Tasks.License();
        l.SetLicense(new MemoryStream(Resources.Aspose_Tasks));

        MemoryStream ms = new MemoryStream(Resources.EmptyProject);
        ms.Position = 0;

        Project project = new Project(ms);
        project.CalculationMode = CalculationMode.None;
        
        project.Set(Prj.Calendar, Aspose.Tasks.Calendar.Make24HourCalendar(project.Calendars.Add("24 Hour")));
        
        Task t1 = project.RootTask.Children.Add("t1");
        t1.Set(Tsk.ConstraintType, ConstraintType.MustStartOn);
        t1.Set(Tsk.Start, Convert.ToDateTime("2018, 06, 11"));
        t1.Set(Tsk.Finish, Convert.ToDateTime("2018, 09, 30"));
      
        Task t2 = t1.Children.Add("t2");
        t2.Set(Tsk.ConstraintType, ConstraintType.MustStartOn);
        t2.Set(Tsk.Start, Convert.ToDateTime("2018, 06, 12"));
        t2.Set(Tsk.Finish, Convert.ToDateTime("2018, 08, 13"));
      
        Task t3 = t1.Children.Add("t3");
        t3.Set(Tsk.ConstraintType, ConstraintType.MustStartOn);
        t3.Set(Tsk.Start, Convert.ToDateTime("2018, 08, 14"));
        t3.Set(Tsk.Finish, Convert.ToDateTime("2018, 09, 30"));
     
        project.CalculationMode = CalculationMode.Automatic;
        project.Recalculate();

        using (FileStream projectStream = new FileStream(destinationPath, FileMode.Create, FileAccess.Write))
        {
            project.Save(projectStream, Aspose.Tasks.Saving.SaveFileFormat.MPP);
        }

Result:
f.e. T1’s duration is showed as „333 days?“ … correct result should be „112 days“.

Can you please give me some advice how to achieve correct duration?
Thank you.

@novotny,

Please share source .mpp file as well for further investigation.

EmptyProject.zip (24.4 KB)

@novotny,

I have worked with source file and sample code and have been able to observe the issue. A ticket with ID TASKSNET-3658 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be addressed.

Hello,
I want to ask you about the ticket TASKSNET-3658.
I don’t want to pressure you, but at the same time I really need to find a way how to deal with the wrong durations. I have tried few more attempts with calculating and setting my duration manually. But the results are still incorrect.
Can you please give me some advice or clue for workaround?
Also providing working project to me would be super nice.
I still do have a feeling this should work fine by default.

Thank you.

Hello @novotny,

We fixed your sample a little, please check it on you side

var l = new License();
l.SetLicense(@"testdata\Aspose.Tasks.lic");

Project project = new Project("EmptyProject.mpp")
{
	CalculationMode = CalculationMode.None
};

project.Set(Prj.Calendar, Calendar.Make24HourCalendar(project.Calendars.Add("24 Hour")));
project.Set(Prj.StartDate, new DateTime(2018, 6, 12, 0, 0, 0));
project.Set(Prj.NewTasksAreManual, false);

Task t1 = project.RootTask.Children.Add("t1");
Task t2 = t1.Children.Add("t2");
t2.Set(Tsk.ConstraintType, ConstraintType.MustStartOn);
t2.Set(Tsk.ConstraintDate, new DateTime(2018, 6, 12, 0, 0, 0));
t2.Set(Tsk.Start, new DateTime(2018, 6, 12, 0, 0, 0));
t2.Set(Tsk.Finish, new DateTime(2018, 8, 13, 23, 59, 59));

Task t3 = t1.Children.Add("t3");
t3.Set(Tsk.ConstraintType, ConstraintType.StartNoEarlierThan);
t3.Set(Tsk.ConstraintDate, new DateTime(2018, 8, 14, 0, 0, 0));
t3.Set(Tsk.Start, new DateTime(2018, 8, 14, 0, 0, 0));
t3.Set(Tsk.Finish, new DateTime(2018, 9, 30, 23, 59, 59));

project.Recalculate();

project.Save(@"AsposeTasksTest.mpp", SaveFileFormat.MPP);

Resulting duration of t1 is 333 days which is the same as MS Project generates for this user scenario.