I have just built a little bit of test code to try and run a mail merge on an example document that has been provided to me by my customer and am getting an exception thrown in the Aspose library (“Object reference not set to an instance of an object”, stack trace below). When I ran this test before having a license it “worked” in that it didn’t throw any exception, but after adding these lines:
License l = new License();
l.SetLicense("c:\Aspose.Words.lic");
it now has a problem. I suspect why it worked without specifying the license before-hand was because it was only processing the first page and didn’t get as far as whatever the bug is that causes the problem.
The merge I’m attempting is fairly complex - the word document has quite a few rules and uses IF, SET, COMPARE etc. Just to be thorough I tested the license with a simple merge document I created in Word and it worked perfectly, so it must be that the Aspose library is crashing during the merge due to the complexity.
Can you please let me know if there is anything I can do to work around the problem below. I really like the look of your product and would be disappointed if it can’t handle the documents we need for this project.
Here is the Stack Trace:
at x28925c9b27b37a46.x98739d759efb5fe7.get_x1be93eed8950d961()
at x28925c9b27b37a46.x98739d759efb5fe7.x8a92b04b9d325900()
at x28925c9b27b37a46.x98739d759efb5fe7.xeea9b43f0c912fdb(Node xda5bf54deb817e37)
at Aspose.Words.Node.x94cfa410ea3bb516()
at xfbd1009a0cbb9842.xe11422ab90fb5f3b.x80766db8f9759629()
at xfbd1009a0cbb9842.xdbc94e34c2e61de1.x1f96778a29980753(x5c928e5f0a98a22c x9af1c2b12bb7a91a)
at xfbd1009a0cbb9842.x2d380f6141585930.x1f96778a29980753()
at xfbd1009a0cbb9842.x2d380f6141585930.x42be32a552bb83b8()
at xfbd1009a0cbb9842.x2d380f6141585930.x2408a6db33935c93()
at xfbd1009a0cbb9842.x985dd08fd338eeea.x1f490eac106aee12(x2d380f6141585930 xbce90b56ab411c23)
at xfbd1009a0cbb9842.x985dd08fd338eeea... ctor(Field field, x5e36356bc92c609b updateContext, x6ed66b5cf8da2955 switchResolver)
at xfbd1009a0cbb9842.x985dd08fd338eeea... ctor(x5e36356bc92c609b updateContext)
at xfbd1009a0cbb9842.x5e36356bc92c609b.x496cb6c60c307cd1()
at Aspose.Words.Fields.Field.x42a25ae95099edb8(x5e36356bc92c609b x0f7b23d1c393aed9)
at Aspose.Words.Fields.Field.x295cb4a1df7a5add(x5e36356bc92c609b x0f7b23d1c393aed9)
at xfbd1009a0cbb9842.xfedf115fd9c03862.x4e3cfc222c92cda7(Field xe01ae93d9fe5a880, x5e36356bc92c609b x0f7b23d1c393aed9)
at xfbd1009a0cbb9842.xfedf115fd9c03862.x4e3cfc222c92cda7(Field xe01ae93d9fe5a880)
at xfbd1009a0cbb9842.xbf9ddf72e1283af9.x18dfca7c5fd2402f()
at xfbd1009a0cbb9842.xfedf115fd9c03862.xdd6cf0348a23f220(xcf417e2db4fe9ed3 xe00c282e1a49fcfb)
at xfbd1009a0cbb9842.xfedf115fd9c03862.xdf269951086089ce(x6435b7bbb0879a04 xa942970cc8a85fd4)
at xe86f37adaccef1c3.xc5c3f438428cb03b.xd01ea9131ba53b87(ArrayList x292b5f49fee42032, xfedf115fd9c03862 xcc5022025f73a533)
at xe86f37adaccef1c3.xc5c3f438428cb03b.xdeeb682062ef79a5()
at xe86f37adaccef1c3.xc5c3f438428cb03b.xd5da23b762ce52a2(MailMerge x2a99de81295e7f29, IMailMergeDataSource xef1769c4fe6ae4ca, Boolean xc9c7b90943167aed)
at Aspose.Words.Reporting.MailMerge.Execute(IMailMergeDataSource dataSource)
at Aspose.Words.Reporting.MailMerge.Execute(String[] fieldNames, Object[] values)
at Aspose.Words.Demos.WebForms._Default.OnLoad(EventArgs e) in C:\Program Files\Aspose\Aspose.Words for .NET\Demos\CSharp\WebForms\Default.aspx.cs:line 94
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
The code I’m using is:
License l = new License();
l.SetLicense("c:\Aspose.Words.lic");
Document doc = new Document("c:\Merge.docx");
String[] names = null;
String[] vals = null;
using(Microsoft.VisualBasic.FileIO.TextFieldParser p = new Microsoft.VisualBasic.FileIO.TextFieldParser("c:\Data.csv"))
{
p.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited;
p.SetDelimiters(",");
p.HasFieldsEnclosedInQuotes = true;
names = p.ReadFields();
vals = p.ReadFields();
}
doc.MailMerge.Execute(names, vals);
doc.Save("c:\Result.pdf");
The input Data.csv file contains 309 name/values for this particular file but for other documents could contain up to about 500.