Date cannot be DateTime.MinValue exception in Project.Recalculate()

I am trying to generate and export .mpp files - which work fine for most situations, but there are a few projects that won't export. What can I check? I don't have any values set to DateTime.MinValue, so I presume this is a calculated value. Error below:


Date cannot be DateTime.MinValue
Parameter name: date

at Aspose.Tasks.Calendar.GetPreviousWorkingDayEnd(DateTime date)
at Aspose.Tasks.Task.(List`1 , List`1 )
at Aspose.Tasks.Task.(List`1 )
at Aspose.Tasks.Task.()
at Aspose.Tasks.ResourceAssignment. ()
at Aspose.Tasks.Task. ()
at ​ .()
at ​ . ​ ​ ()
at Aspose.Tasks.Task.()
at .(Task )
at .()
at .()
at Aspose.Tasks.Project.Recalculate()

A bit more information - I don’t know if it is related - but I am building my own calendar for the project. What I have noticed is while I am adding Aspose.Tasks.WorkingTime 1 by 1 to the WorkingTimes property of a Aspose.Tasks.WeekDay, then it seems to ignore everything after the 5th WorkingTime added. This is a problem for any project longer than 35 days…

Hi,

Thank you for contacting Aspose support team.

I have tried to re-produce the issue with following sample code using Aspose.Tasks for .NET 17.3.0 but could not re-produce the issue. Could you please give a try to the sample code and share the feedback. If it is not as per your scenario, please modify it or provide your sample console application which can be compiled and executed here for re-producing the scenario. Also send any template MPP file which is used for creating the MPP file. It will help us to observe the issue and provide assistance accordingly.

Project proj = new Project(@“blank2010.mpp”);
Calendar cal = proj.Calendars.Add("TestCal");
proj.Set(Prj.Calendar, cal);
List<WorkingTime> wt = new List<WorkingTime>()
{
    new WorkingTime() { FromTime = new DateTime(1,1,1,8, 0, 0), ToTime = new DateTime(1,1,1, 13, 0, 0) },
    new WorkingTime() { FromTime = new DateTime(1,1,1,14, 0, 0), ToTime = new DateTime(1,1,1, 17, 0, 0) },
};
WeekDay mon = new WeekDay(DayType.Monday, wt);
WeekDay tue = new WeekDay(DayType.Tuesday, wt);
WeekDay wed = new WeekDay(DayType.Wednesday, wt);
WeekDay thu = new WeekDay(DayType.Thursday, wt);
WeekDay fri = new WeekDay(DayType.Friday, wt);
cal.WeekDays.Add(mon);
cal.WeekDays.Add(tue);
cal.WeekDays.Add(wed);
cal.WeekDays.Add(thu);
cal.WeekDays.Add(fri);
Task tsk1 = proj.RootTask.Children.Add("Task 1");
tsk1.Set(Tsk.Start, new DateTime(2017, 5, 21, 8, 0, 0));
tsk1.Set(Tsk.Finish, new DateTime(2017, 12, 21, 8, 0, 0));
proj.Recalculate();
proj.Save(@"output.mpp", SaveFileFormat.MPP);

I have managed to get Recalculate() to run successfully for this project. The times for some Working Times were overlapping by a second and when I rounded all the times in the Calendar to the nearest minute the problem went away.


However, it takes 16 minutes to run the recalculate for 2,800 Tasks, and that is not including the 1931 links(dependencies). Including the links before recalculating takes over 40 minutes - I gave up waiting for it.

Is that normal to take that long to run the recalculate??

I have replaced the dynamic working times per day with the below code and it now runs in 2.5 mins (including links + resources).


foreach (var day in quantumCalendar.WeekDays)
{
day.FromDate = scheduleData.ShiftPeriods.Min(x => x.StartTime).LocalDateTime;
day.ToDate = scheduleData.ShiftPeriods.Max(x => x.FinishTime).LocalDateTime;
day.WorkingTimes.Add(new WorkingTime { FromTime = new DateTime(1,1,1, 6,0,0), ToTime = new DateTime(1,1,1, 18,0,0) });
day.WorkingTimes.Add(new WorkingTime { FromTime = new DateTime(1,1,1, 18,0,0), ToTime = new DateTime(1,1,2, 6,0,0) });
day.DayWorking = true;
}

I am confused with how the WorkingTimes work. How would I normally create a calendar with 2 or 3 shifts a day that runs continuously for over a month? Particularly paying attention to the Start Time (say 6am on Monday 1st May 2017) and Finish Time? (eg 6am on Tuesday 6th June 2017)

Hi,

Aspose.Tasks has tried to implement the best possible calculation engine while recalculating the projects. However, based on the complexity of the tasks, task links, constraints, resources and calendars, it may take more time while re-calculating the project. You also may try different calculation mode to achieve the best performance as mentioned here.

You can create 24 hours calendar using following sample code.

var asposeCalendar = _project.Calendars.Add(“24hourCal”);

Calendar.Make24HourCalendar(asposeCalendar);

Regarding setting the calendar with times from 06:00 am to 06:00 am, you may please create such calendar in Microsoft project with few sample tasks using this calendar, and send us the MPP and XML versions of the same project. It will help us to observe the sample data and provide assistance using it in Aspose.Tasks.

Hi

Here is a simplified sample project that recreates the error.
Exporter.zip (67.1 KB)

Cheers

@JumpingJezza,

Thank you for writing to Aspose support team.

We are working on this issue however it is little difficult to identify issue with large number of tasks and lengthy code. Could you please assist us in re-producing the issue by simplifying the code up to maximum extent and also please reduce the data in CSV files as much as possible? Simple code and less data will help us to observe the problem and provide assistance accordingly.

I’m terribly sorry but the code is already hugely simplified from the code we are actually using. As I said before, this exception only happens on certain datasets; this is the smallest dataset I could find. It has taken a very long time to get it to be consistently reproducible in a test project.

@JumpingJezza,

We have further investigated the issue and observed that you have set the Project.CalculationMode after all the changes in the project data. This call should be made before any change in data like immediate after crating the project. Please modify your code as below and share the feedback.

public async Task<Project> RunExportAsync()
{
    //load data
    var tasksAndActivities = await Task.FromResult(LoadTasksAndActivities());
    var teams = await Task.FromResult(LoadTeamsAsync());
    var resources = await Task.FromResult(LoadResourcesAsync());
    var locations = await Task.FromResult(LoadLocationsAsync());
    var workOrders = await Task.FromResult(LoadWorkOrdersAsync());
    var links = await Task.FromResult(LoadLinksAsync());
    //load template project file
    var project = CreateProject();
    //calculate
    project.CalculationMode = CalculationMode.Manual;//Set calculation mode prior to any changes in project data
    UpdateProjectHeader(project, tasksAndActivities);
    //add extended attributes to the project file
    AddTeamExtendedAttribute(project, teams);
    AddLocationExtendedAttribute(project, locations);
    AddWorkOrderExtendedAttribute(project, workOrders);
    //add the data to the project file
    AddTasksAndActivities(project, tasksAndActivities, teams, resources, locations, workOrders);
    AddLinks(project, links);
    //calculate
    //project.CalculationMode = CalculationMode.Manual;
    project.Recalculate();
    //return for saving
    return project;
}

That is correct that we set the calculation mode at the end. If it is set to Manual before adding the data as you suggest, then it recalculates for every task that is added - making it unforgivably slow (about 2 minutes for this small dataset). It sometimes also throws an OutOfMemory Exception.

@JumpingJezza,

Regarding the performance issue, Aspose.Tasks has tried to implement best possible computation engine for handling the tasks. However sometimes due to complexity of task links, calendars and constraints etc. it may take time to accomplish a job. As all Microsoft Project documents are not public , therefore it cannot be exact replica of the product. Aspose.Tasks has provided different calculation modes which can be used according to the requirements like Mode None can be used for best performance. You may please visit here to get more information about the modes.

I am afraid that no exception is raised here with the available data set. You may please provide a data set which can be used to re-produce the issue here. We will try to observe the problem and provide assistance accordingly.

  • Using calculation mode = Manual the Dataset raises an exception every time I run it. It happens on the 15th row of the data of the task called “C/O 48WK Conv BCV110 Hard Skirts” on line 390 -> newTask.Set(Tsk.Start, split.Start.LocalDateTime); The exception is System.OutOfMemoryException. If I change the application to run as 64 bit, it runs forever at 97% memory usage instead without completing the project.
  • Using calculation mode = None the Dataset raises an exception every time I run it. It happens on project.Recalculate(); The exception is System.ArgumentOutOfRangeException. Date cannot be DateTime.MinValue

I am using Visual Studio 2015.

Can you please attach the modified solution you are using that does not raise exceptions?

@JumpingJezza,

We used the same code as shared with you earlier and the dataset is also the same. Could you please make sure you are using the latest version of the API at your end? In both cases, we didn’t face any exception at our end.

As you can see by the nuget packages.config file I am using version 17.8

@JumpingJezza,

Issue of hanging the application while using manual mode is re-produced and logged under Id:TASKSNET-2104 for further investigation by the product team. You will be automatically notified once any update is received in this regard.

Regarding the issue in None mode, we are discussing this issue here and will write back soon once the feedback is ready to share.

Is there any update yet on the problem in None mode?

Also, I can see that TASKSNET-2104 is resolved - how do I see the details of it?

@JumpingJezza,

Thank you for contacting Aspose support team again.

This issue is resolved and will be part of our next release Aspose.Tasks for .NET 17.9 expected in couple of weeks. You will be automatically notified once new version is released and available online for download.

@JumpingJezza,

This issue has been fixed in latest version of Aspose.Tasks for .NET 17.9. Please let us know if we can be of any additional help to you with respect to your queries related to API.