Brep.CreateFromSweep Erratic Results

I am having a hard time getting this curve to sweep. Is there certain criteria I need met to get a successful sweep ? It looks like each segment is pointing in different directions. I tired to use Simplify() but that didnt do much same with rebuild. Can someone explain how sweep works fundamentally ? Is there a way to rework or rebuild the curve where it would generate a clean sweep ?

Sweep (4.5 KB)

Thanks !

You seem to have forgotten the Internalise of the first Curve.

I suspect it’s because the rail curve has too sharp bends for the profile, creating a crumpled, self-intersecting surface. When in doubt, bake the rail and profile and run the normal Sweep1 command in Rhino and look at the results.