We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Document MailMerge null reference exception

I’m trying to debug a MailMerge exception and am not able to determine what is causing the problem. I am inserting some HTML into the document prior to performing the merge. Something in this particular HTML is causing a null reference exception during the subsequent merge, but I haven’t been able to figure out which part is causing the problem.

Attached is a sample program that illustrates the issue. I am using Aspose.Words

DocumentTest.zip (71.2 KB)

Any help would be much appreciated.


After an initial test with the licensed latest version of Aspose.Words for .NET i.e. 18.10, we were unable to reproduce this issue on our end (see 18.10.zip (28.9 KB)). So, we would suggest you please upgrade to the latest version of Aspose.Words for .NET. Hope, this helps.

We used the following code on our end for testing.

Document doc = new Document("D:\\DocumentTest\\am protocol summary template consent.docx");

// This example creates a table, but you would normally load table from a database. 
string testHtml = File.ReadAllText("D:\\DocumentTest\\field.txt");

var builder = new DocumentBuilder(doc);

//string[] fields = new string[] {"_attribute0", "htmlcontent:_attribute323._introduction", "_attributeSF02._attribute1" };
//string[] values = new string[] { "foobar", "", "30" };
string[] fields = new string[] { "_attribute0", "_attributeSF02._attribute1" };
string[] values = new string[] { "foobar", "30" };

// Field values from the table are inserted into the mail merge fields found in the document.
doc.MailMerge.Execute(fields, values);