Getting object reference error GetTimephasedWork for baseline if resources are not added

Hello Aspose Team,

I’m encountering an “Object reference not set to an instance of an object” error when calling GetTimephasedWork for AssignmentBaselineWork in Aspose.Tasks when there are no resources assigned to the task.

This functionality worked correctly in version 25.7.0, but it fails in version 25.9.0.

My requirement is to retrieve time-phased work values even when no resources are assigned to the task. Currently, I am using the Microsoft Interop library, which provides TimeScaleData in 6-hour intervals without requiring resource assignments. However, with Aspose.Tasks, time-phased work is only returned when at least one resource is assigned, which is causing the issue.

Is there any way to retrieve time-phased work in Aspose.Tasks without resource assignments, similar to Interop? Or is there a recommended approach or configuration to achieve this in the latest release?

@ikhan.pathan

Summary
Assignment.GetTimephasedWork(..., TimephasedDataType.AssignmentBaselineWork) works only on an existing assignment object. If a task has no resource assignments, there is no Assignment instance to call the method on, so a null‑reference error is thrown.

Why it happens
The method is defined on the Assignment class. When the Assignments collection of a task is empty, any attempt to iterate over it and call GetTimephasedWork results in a call on a null reference. The SDK does not automatically fall back to a task‑level baseline value.

What to do next

  1. Check for assignments before calling the method
if (task.Assignments.Count == 0)
{
// No assignments – use the task‑level baseline work instead
var taskBaselineWork = task.GetTimephasedWork(
shiftStart, shiftEnd, TimephasedDataType.TaskBaselineWork);
}
else
{
// Aggregate work from each assignment
TimeSpan totalBaseline = TimeSpan.Zero;
foreach (var assignment in task.Assignments)
{
totalBaseline += assignment.GetTimephasedWork(
shiftStart, shiftEnd, TimephasedDataType.AssignmentBaselineWork);
}
}

The TaskBaselineWork option returns the baseline work stored for the task itself, which is present even when no resources are assigned.

  1. Verify that baseline work is defined
    Open the project file in Microsoft Project (or via Interop) and confirm that the Baseline Work field for the task contains a value. If it is empty, neither the task‑level nor the assignment‑level call can produce a result.

  2. Consider adding a placeholder assignment
    If you need assignment‑level time‑phased data for tasks that currently have no resources, you can create a dummy assignment (e.g., a “None” resource) so that the Assignment API can be used.

  3. Report the behavior to Aspose support
    If the null‑reference exception is unexpected for your scenario, provide a minimal reproducible example (project file, code snippet, stack trace) to Aspose support. They can confirm whether this is a regression and advise on a fix or a future release.

  4. Keep the guard logic reusable
    Encapsulate the above check in a helper method so that all parts of your code handle tasks without assignments consistently.

Note: The information above is based on the documented usage of GetTimephasedWork for assignments and the observed need to use the task‑level baseline when no assignments exist.

:warning: I could not fully verify this explanation against the retrieved sources. Please double-check the behaviour in your environment and confirm the exact SDK/version.

I’ve checked with 25.9 and test project with task without resources assigned and exception " Object reference not set to an instance of an object" is not thrown when GetTimephasedWork is called.

Can you attach a compilable code sample and input MPP file so we can reproduce the issue on our side?

This method is not available at task level.

I noticed an issue when working with one of my client’s .mpp files. For tasks where TimePhasedData has a type of AssignmentBaselineWork, the dType value is returned as null. As a result, I encounter a “Object reference not set to an instance of an object” exception when trying to access the time-phased work.

Additionally, I’m unable to reproduce this scenario by generating sample .mpp file. The sample files do not contain tasks that demonstrate this behavior. The tasks always return TimePhasedData with AssignmentBaselineWork. This makes it difficult to debug and identify the root cause.

var dType= assignment.TimephasedData.FirstOrDefault(e => e.TimephasedDataType == TimephasedDataType.AssignmentBaselineWork);
if (dType != null)
{
    var baselineWork1 = assignment.GetTimephasedWork(shift.ShiftStart, shift.ShiftEnd, TimephasedDataType.AssignmentBaselineWork);
    var baselineWorkSum1 = baselineWork1.TotalHours;
}

@ikhan.pathan ,
you can create a project, add a task, and not set any baseline.
ResourceAssignment.TimephasedData in the project will not contain items with TimephasedDataType.AssignmentBaselineWork.