mainCanvas.GetComponent (). rect.xMin gives the minimum position of the canvas in canvas space, and not in world space. Therefore, if you add xMin to the x position of the canvas, you will get the minimum x position of the canvas in world space. And the same goes for y.
So,
float minX = mainCanvas.GetComponent<RectTransform>().position.x + mainCanvas.GetComponent<RectTransform>().rect.xMin;
float maxY = mainCanvas.GetComponent<RectTransform>().position.y + mainCanvas.GetComponent<RectTransform>().rect.yMax;
float z = mainCanvas.GetComponent<RectTransform>().position.z;
Vector3 topLeft = new Vector3(minX, maxY, z);
will provide you the upper left side of the canvas
Edit: https://docs.unity3d.com/ScriptReference/RectTransform-rect.html
Unity, , RectTransform.rect ,