Intersecting Surface and Brep result incorrect

I have a script which creates a surface and intersects it with a brep. Normally the resulting curves are correct but in some cases not. Below is a screen shot. The grey surface is the brep, aqua are the intersection surfaces. My script creates the red curves. If I intersect the surfaces and brep manually I get the correct yellow curves. Any idea why this is happening?

xsurf = NurbsSurface.CreateFromCorners(New Point3d(wlcorners(0).X + n * interval, res.WaterlineLength, 0), New Point3d(wlcorners(0).X + n * interval, -res.WaterlineLength, 0), New Point3d(wlcorners(0).X + n * interval, -res.WaterlineLength, -res.WaterlineLength), New Point3d(wlcorners(0).X + n * interval, res.WaterlineLength, -res.WaterlineLength))
    If Intersect.Intersection.BrepSurface(brep, xsurf, 1, xsection, Pts) Then
        For k = 0 To UBound(xsection)
    End If

Sorry discovered the error myself. It has to do with the tolerances.

If Intersect.Intersection.BrepSurface(brep, xsurf, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance, xsection, Pts) Then

works perfectly.

Thanks for updating the tread. Let us know if you run into anything else.

– Dale