I'm using version 18.104.22.168 and have the following procedure to copy loops and segments from one container to another:
private void CopySegmentAndLoops(LoopContainer inputContainer, LoopContainer outputContainer, bool copyChildLoops)
int inputSegmentCount = inputContainer.Segments.Count();
for (int i = 0; i < inputSegmentCount; i++)
int inputLoopCount = inputContainer.Loops.Count();
for (int i = 0; i < inputLoopCount; i++)
if (copyChildLoops == true)
CopySegmentAndLoops(inputContainer.Loops.ElementAt(i), outputContainer.Loops.ElementAt(i), true);
catch (Exception err)
There seem to be an issue where at times the AddSegment and AddLoop methods don't actually add anything and don't throw an error. The output container seems to be initialized and the input container has 3 segments and 2 loops. However, under
some undetermined situation the output container object doesn't seem to have anything in it after calling the respective add method. I've run this over several loops and it seems to work most of the time. The reason I found this is that I get and
exception when I call outputContainer.Loop.ElementAt(i). It throws and index out of range (count of output container is 0).
I got this code from http://x12parser.codeplex.com/discussions/355921 by alder 8.