Unexpected Behaviour from NavMesh.CalculatePath

Hi,
I am trying to calculate a path, and then the length of this path between two arbitrary positions on a NavMesh. The function NavMesh.CalculatePath always claims to have found a path by returning true, but the path has 0 corners, and thus 0 length. Has anybody encountered this behaviour/Is this expected behaviour? I have tried this in a minimal test environment with the same results. I will attach a script to demonstrate.
I’d also like to mention the issue doesn’t seem to be the NavMesh setup, an agent placed in the world behaves exactly as expected.
Thanks for any help

public class test : MonoBehaviour
{
    public GameObject obj1;
    public GameObject obj2;

    // Update is called once per frame
    void Update()
    {    
        NavMeshPath path = new NavMeshPath();
        bool worked = NavMesh.CalculatePath(obj1.transform.position, obj2.transform.position, NavMesh.AllAreas, path);
        Debug.Log(worked);
        float pathLength = 0;
        for ( int i = 0; i < path.corners.Length - 1; i++)
        {
            pathLength += Vector3.Distance(path.corners*, path.corners[i+1]);*

}
Debug.Log(pathLength); //path.corners.Length always = 0, and of course pathLength always = 0
}

}

With some research I discovered the issue may be that the objects transform.position don’t lie exactly on the NavMesh plane. The solution to this is to use NavMesh.SamplePosition() which finds a point on the NavMesh that is nearest to a given transform Unity - Scripting API: AI.NavMesh.SamplePosition ,
for example:

NavMeshPath FindPathBetweenGameObjects (GameObject a, GameObject b)
{
    NavMeshPath path = new NavMeshPath();
    Vector3 AtoB = (b.transform.position - a.transform.position).normalized;
    NavMesh.SamplePosition(a.transform.position, out NavMeshHit hitA, 10f, NavMesh.AllAreas);
    NavMesh.SamplePosition(b.transform.position, out NavMeshHit hitB, 10f, NavMesh.AllAreas);
    bool foundPath = NavMesh.CalculatePath(hitA.position, hitB.position, NavMesh.AllAreas, path);

    return path
}