ERROR: StartIndex cannot be less than zero. Parameter name: startIndex

My code was working fine and suddenly I started getting the message above
here is the code:
var serializer = new XmlSerializer(typeof(PrintPaymentRecord));
var stream = new MemoryStream();
serializer.Serialize(stream, PrintRecord);
//create xml from the stream
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
stream.Position = 0;
var xml = reader.ReadToEnd();
DataSet ds = new DataSet();
ds.ReadXml(new StringReader(xml));

doc.MailMerge.FieldMergingCallback = new HandleMergeField();
doc.MailMerge.UseNonMergeFields = true;
doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedFields;
//mail merge
doc.MailMerge.ExecuteWithRegions(ds);
The error occurs on the last step
I’ve attached the xml file generated by the code

Hi Michael,


Thanks for your inquiry. Please attach the following resources here for testing:

  • Your input Word document
  • Please create a standalone Console application (source code without compilation errors) that helps us reproduce your problem on our end and attach it here for testing…

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click ‘Reply’ button that will bring you to the ‘reply page’ and there at the bottom you can include any attachments with that post by clicking the ‘Add/Update’ button.

Best regards,