Exception on Document.MailMerge.ExecuteWithRegions(DataTable)

We get an exception when performing MailMerge.ExecuteWithRegions with a DataTable as parameter. The stack trace:


Index and length must refer to a location within the string.
Parameter name: length
at System.String.Substring(Int32 startIndex, Int32 length)
at Aspose.Words.Run.x4ede2f7ca43a1460(Int32 xd4f974c06ffa392b, Int32 x961016a387451f05, Boolean x1e2b473fecc8c6b6)
at x28925c9b27b37a46.xb56968f92e308c8a.x64ae56857b252b27(xe83a6b069ec8efc2 xcbf24c118ac8aa0b, Boolean xdd2a9ff3a1da2f60)
at x28925c9b27b37a46.x0a28863c804404d7.xb3491b205d3b163a()
at x28925c9b27b37a46.xce798d32ec270dda.x267efc5f6ada2866()
at xfbd1009a0cbb9842.xca592a476766b11a.xb333e1e6c01c2be2()
at Aspose.Words.Fields.Field.x295cb4a1df7a5add(x5e36356bc92c609b x0f7b23d1c393aed9)
at xfbd1009a0cbb9842.xfedf115fd9c03862.x4e3cfc222c92cda7(Field xe01ae93d9fe5a880, x5e36356bc92c609b x0f7b23d1c393aed9)
at xfbd1009a0cbb9842.xbf9ddf72e1283af9.x18dfca7c5fd2402f()
at xfbd1009a0cbb9842.xfedf115fd9c03862.xdf269951086089ce(x6435b7bbb0879a04 xa942970cc8a85fd4)
at xe86f37adaccef1c3.xc5c3f438428cb03b.xdeeb682062ef79a5()
at Aspose.Words.Reporting.MailMerge.ExecuteWithRegions(IMailMergeDataSource dataSource)

What can cause this? I’ve checked the content of the DataTable, and that looks fine at first glance.

We use a fairly old version of Aspose.Words (DLL has file version 9.7.0.0 and product version 2011.02.05).

Hi Kilian,

Thanks for your inquiry. I would suggest you please upgrade to the latest version (v15.5.0) from here and let us know how it goes on your side. If the problem still remains, please share following detail for investigation purposes.


  • Please attach your input Word document.
  • Please

    create a standalone/runnable simple application (for example a Console
    Application Project
    ) that demonstrates the code (Aspose.Words code) you used to generate
    your output document.

Hi Tahir,

The latest version works, but unfortunately our license does not allow the upgrade. After a lot of testing, it seems there was a specific (malformatted?) IF-merge field in the document that caused this error. Fortunately, we can work around that.

Hi Kilian,

It is nice to hear from you that you have found the solution of your issue. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.