I am trying to concatenate several byte arrays into one. I have hit upon a roadblock, where my tests show that I cannot copy more than two arrays into a different array at the same time. Here's what I have tried:

1. Read file1 into byte array1.
2. Read file2 into byte array2.
3. Read file3 into byte array3.
4. Create a byte arrayTotal with length equal to array1.length + array2.length + array3.length
5. Use Buffer.BlockCopy to copy contents of array1 to arrayTotal. Works fine.
6. Use Buffer.BlockCopy to copy contents of array2 to arrayTotal. Works fine.
7. Use Buffer.BlockCopy to copy contents of array3 to arrayTotal. Fails.

I tried using Array.Copy instead of Buffer.BlockCopy with identical results. The only solution I have found so far is:

4. Create a byte arrayTotal1 with length equal to array1.length + array2.length.
5. Use Buffer.BlockCopy / Array.Copy to copy array1 to arrayTotal1.
6. Use Buffer.BlockCopy / Array.Copy to copy array2 to arrayTotal1.
7. Create a byte arrayTotal2 with length equal to arrayTotal1.length + array3.length.
8. Use Buffer.BlockCopy / Array.Copy to copy arrayTotal1 to arrayTotal2.
9. Use Buffer.BlockCopy / Array.Copy to copy array3 to arrayTotal2.

Can anyone shed light on why this is happening and what is the solution to it?

[Note: There is no mistake in the offsets. With just two arrays the code works perfectly. With three arrays, the copy works perfectly till I copy the third array. I have verified this through my functional tests as well as going through random elements in the source and destination arrays in the debugger.]

.