ArgumentOutOfRangeException when loading MPP files with Material resources

Product: Aspose.Tasks for .NET
Version: 25.8.0
Environment: .NET 8.0, Windows

MPP files containing Material type resources crash Aspose.Tasks immediately during Project constructor. The issue occurs because Material resources in MS Project have null calendars (which is correct - materials don’t follow work schedules), but Aspose.Tasks tries to access WorkingTimeCollection on these null calendars.

Error:

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at Aspose.Tasks.WorkingTimeCollection.get_Item(Int32 index)
   at [internal Aspose.Tasks resource assignment processing]
   at Aspose.Tasks.Project..ctor(Stream stream, LoadOptions options)

Reproduction:

  1. Load any MPP file containing Material type resources
  2. Code: new Project(stream, new LoadOptions())
  3. Immediate crash - cannot catch or handle

Root Cause: In MS Project:

  • Work resources have calendars (working hours)
  • Material resources have NO calendars (they’re consumed, not scheduled)
  • This is valid and expected behavior

Aspose.Tasks incorrectly tries to access WorkingTimeCollection[index] on null calendars for Material resources.

Impact: - Cannot load any MPP files with material resources. No workaround exists as crash occurs in binary parser before we can access the Project object. Common in construction/manufacturing projects.

Note:

  • XML export from same MPP file loads fine (different parser path)
  • Similar root cause to TASKSNET-11532 (Material resource handling) but occurs earlier - during file load rather than when reading timephased data

@jayrich

It seems you’re encountering an ArgumentOutOfRangeException when trying to load MPP files that contain Material type resources. This issue arises because Aspose.Tasks attempts to access the working time collection of a null calendar associated with these resources, which is not valid since Material resources do not have calendars.

Here’s a step-by-step plan to address this issue:

  1. Check for Updates: Ensure you are using the latest version of Aspose.Tasks. Sometimes, issues like this are resolved in newer releases.

  2. Error Handling: Since the exception occurs during the loading of the project, you might not be able to catch it directly. However, you can use the TasksReadingException class to log the error details. This can help identify if there are specific resources causing the issue.

    Here’s a sample code snippet to implement error handling:

    Project project;
    try
    {
        project = new Project("path_to_your_file.mpp");
    }
    catch (TasksReadingException ex)
    {
        Console.WriteLine("Message: " + ex.Message);
        Console.WriteLine("Log: " + ex.LogText);
        if (ex.InnerException != null)
        {
            Console.WriteLine("Inner exception message: " + ex.InnerException.Message);
        }
    }
    
  3. Alternative Loading: If the MPP file is consistently causing issues, consider exporting the project to XML format (if possible) and then loading that XML file instead, as you mentioned that it loads fine.

  4. Contact Support: If the problem persists, reach out to Aspose support with the problematic MPP file. They can provide more specific guidance or a fix if it’s a known issue.

Next Steps: Implement the error handling code and check for updates. If the issue continues, try loading the XML version of the project. If none of these solutions work, contact Aspose support for further assistance.

Please let me know if this helps or if you have any further questions!

@jayrich ,

I’ve checked the scenario using MPP file containing Material type resources and assignments of Material resources, but cannot observe the crash.

Can you attach MPP file so we can reproduce the issue?