Trouble capping planar brep

HI There,

Was wondering if there is a simple solution or answer to why some planar breps dont close in rhinocommon but will close manually.

Here is the code for the class - function.

``````//function to extrude in world z axis segmentstojoin by height
public static Brep[] extrudeedgebeam(Curve[] segmentstojoin, double height)
{

//create brep array
Brep[] extrudededgebeam = new Brep[segmentstojoin.Length];

//loop through segmentstojoin and extrude
for (int i = 0; i < segmentstojoin.Length; i++)
{
//find bbox centre point of segmentstojoin
BoundingBox bbox = segmentstojoin[i].GetBoundingBox(true);
Point3d centrepoint = bbox.Center;

//new curve duplciate of segmentstojoin
Curve newcurve = segmentstojoin[i].DuplicateCurve();

//move segmentstojoin in world z axis by height
newcurve.Translate(new Vector3d(0, 0, height));

//create new point moved in world z axis by height
Point3d newpoint = centrepoint + new Vector3d(0, 0, height);

//extrude segmentstojoin
extrudededgebeam[i] = Brep.CreateFromLoft(new Curve[] { segmentstojoin[i], newcurve }, Point3d.Unset, Point3d.Unset, LoftType.Tight, false)[0];

//move in z axis by - half height
extrudededgebeam[i].Translate(new Vector3d(0, 0, -height / 2));

//create surface from newcurve
Surface newSurface = Surface.CreateExtrusion(newcurve, new Vector3d(0, 0, 1));

//create surface from segmentstojoin[i]
Surface newSurface2 = Surface.CreateExtrusion(segmentstojoin[i], new Vector3d(0, 0, 1));

//join extrudededgbeam[i] and newsurface1 and newsurface2
Brep[] joinedbreps = Brep.JoinBreps(new Brep[] { extrudededgebeam[i], newSurface.ToBrep(), newSurface2.ToBrep() }, 0.01);

extrudededgebeam[i] = joinedbreps[0];

}

return extrudededgebeam;
}
``````

Noting I tried close planar and didnt work. So started to try making individual surfaces from top and bottom and join back together. Individual surface dont work either.

Please note I am a noob.