Swp1 on polyline produces invalid brep, can’t split brep

I’m trying to Swp1 the same polyline with two rectangular profiles and then replace some of its sections with each other (something like in the picture). The problem is Swp1 returns an invalid brep that I can’t later split on the corners. Any ideas about what I’m doing wrong? Thank you!

SWP1 PROBLEM.gh (25.9 KB)

Dear @Pawel1

The section you are extruding through the rail is too big, so the sweep is intersecting by itself and an invalid brep is obtained. You must reduce the section of your rectangle!