If stringBulider length is 0
fieldNames.Remove(fieldNames.Length - 1, 1);
the above code will not work.
So before run the above code please check whether the stringbuilder length is not equal t zero.
This error is coming because your are assigning the start index less than zero.
The start index is always greater than zero.