Strange, unreadable, error message

We are getting a strange stack trace when trying to print some data using MailMerge.Execute:

Message: Object reference not set to an instance of an object.

at .(Boolean )
at .(Boolean )
at .( )
at .( , Int32 )
at .( )
at .( )
at .( , Int32 )
at .( , Int32 , Boolean )
at .( , Int32 , Boolean )
at ​ .()
at ​ .(​ , Int32 , Boolean , Boolean )
at ​ .( )
at .( , Int32 , Boolean )
at .( , Int32 , Boolean )
at ​ .()
at ​ .(​ , Int32 , Boolean , Boolean )
at ​ .( )
at .( , Int32 , Boolean )
at .( , Int32 , Boolean )
at ​ .()
at ​ .(​ , Int32 , Boolean , Boolean )
at . ()
at .( , Int32 )
at .( )
at .()
at .( )
at .(​ )
at .(Boolean )
at .(Boolean )
at . ()
at .(Document , )
at . ()
at .( )
at .( , )
at . ()
at Aspose.Words.MailMerging.MailMerge.( )
at Aspose.Words.MailMerging.MailMerge.Execute(String[] fieldNames, Object[] values)
at SERV.Business.AssignmentPrinter.PrintNotes(Int32 assignmentId) in C:\Projects\SERV\Development\WebApplication\SERV.Business\Printing\AssignmentPrinter.vb:line 215
at SERV.Business.AssignmentPrinter.PrintAssignment(Dictionary`2 dataToPrintCategories) in C:\Projects\SERV\Development\WebApplication\SERV.Business\Printing\AssignmentPrinter.vb:line 134
at SERV.Web.Areas.Print.Controllers.PrintController.PrintAssignment(FormCollection form) in C:\Projects\SERV\Development\WebApplication\SERV.Web\Areas\Print\Controllers\PrintController.vb:line 67

It seems to be related to an HTML table that is in the text being printed.

Here is the source:

		Dim assignment = _assignmentRepository.GetByIdWithIncludes(assignmentId,
							New AssignmentIncludes().Documentations().DocumentationTags() _
								.AssignmentGroup())

		Dim notes = assignment.Documentations.
				Where(Function(x) x.DocumentationTypeId = DocumentationTypeEnum.Note).
					OrderBy(Function(x) x.CreateDate)

		'Data for headers/footers
		Dim assignmentData = New Dictionary(Of String, String)
		With assignmentData
			.Add("AssignmentId", assignment.AssignmentId.ToString())
			.Add("DBA", assignment.AssignmentGroup.DBA)
			.Add("AccountId", assignment.AssignmentGroup.AccountId.ToAccountIdFormat())
			.Add("UBI", assignment.AssignmentGroup.UBI)
			.Add("UserId", assignment.UserId)
		End With

		'Data for the report
		Dim notesData = notes.Select(Function(x) New With {
				.DocumentText = x.DocumentationText,
				.UserId = x.UserId,
				.Tags = x.Tags.Select(Function(y) y.TagText).ToList().JoinStrings(", "),
				.CreateDate = x.CreateDate.ToShortDateString(),
				.CreateTime = x.CreateDate.ToShortTimeString()})

		Dim notesDataSource = New MailMergeDataSource(notesData, "Notes")

		Dim doc = CreateDocument("DocumentationNotesReport.dotx")

		doc.MailMerge.FieldMergingCallback = New HandleMergeFieldInsertHtml()
		doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedRegions

		doc.MailMerge.ExecuteWithRegions(notesDataSource)

		doc.MailMerge.UseNonMergeFields = True
		doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveEmptyParagraphs Or
									   MailMergeCleanupOptions.RemoveContainingFields Or
									   MailMergeCleanupOptions.RemoveUnusedFields

		doc.MailMerge.Execute(assignmentData.Keys.ToArray(), assignmentData.Values.ToArray())

		RemoveEmptyParagraphs(doc)

		Return doc

The error occurs on the line “doc.MailMerge.Execute(…”

When we remove the HTML table from the text to be printed, no error is thrown.

Please ignore the above question. We figured out the problem. I don’t see anyway to delete the original question though.

@camainc

Thanks for your feedback. It is good to know that you have managed to resolve your issue at your own. We have closed this ticket.

Please keep using our API and feel free to contact us for any further assistance.

Best Regards,