Throw Object Reference Not Set to an Instance of an Object When Doing Word Mail Merge

Hi,
We use Aspose.Words to generate word report. Currently we use v9.2, but we want to upgrade to v9.8. When we tested report generation using v9.8, the generation failed. By debugging, I found the exception “object reference not set to an instance of an object” was thrown, when calling Document.MailMerge.Execute(string[] fieldNames, object[] values) method. The callstack is below:

at x4adf554d20d941a6.x5c28fdcd27dee7d9.get_x9a05d8dab0f0619f() at x4adf554d20d941a6.x61c61e304d8f82bf.xef8721f06e48b9f3() at x4adf554d20d941a6.x61c61e304d8f82bf.x408f4b7efc86fd49() at x4adf554d20d941a6.xeefdffd909e695da.x408f4b7efc86fd49() at x4adf554d20d941a6.xeefdffd909e695da.xc3819e13f60dd8e6(Boolean xfad304b5f8f3bb5b) at x59d6a4fc5007b7a4.xcde671c53995c411.xd9db07500873ae98(Document x3664041d21d73fdc, xdeb77ea37ad74c56 xdfde339da46db651) at Aspose.Words.Document.UpdatePageLayout() at xfbd1009a0cbb9842.xe70a81b27884f7a0.xb333e1e6c01c2be2() at xfbd1009a0cbb9842.xbf9ddf72e1283af9.x18dfca7c5fd2402f() at xfbd1009a0cbb9842.xfedf115fd9c03862.xdd6cf0348a23f220(xcf417e2db4fe9ed3 xe00c282e1a49fcfb) at xfbd1009a0cbb9842.xfedf115fd9c03862.x118a2acc122f2bb3() 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 ConsoleApplication2.Program.Main(String[] args) in C:\Documents and Settings\sheng-ye\My Documents\Test For Markups\Test For Markups\ConsoleApplication2\Program.cs:line 52

It is very strange. It works finely in old version(9.2), while failed in newer version.
The code is below:

try
{
    License license = new Aspose.Words.License();
    license.SetLicense("Aspose.Total.lic");
    Document doc = new Document(@"DEDirectPromiseMasterTemplate.doc");
    Dictionary <string, object> dataSource = new Dictionary <string, object> ();
    foreach(string fieldName in doc.MailMerge.GetFieldNames())
    {
        if (dataSource.ContainsKey(fieldName))
            continue;
        if (fieldName.Contains("$"))
        {
            dataSource.Add(fieldName, true);
        }
        else if (fieldName == "BITAG")
        {
            dataSource.Add(fieldName, new DateTime(2011, 12, 31));
        }
        else if (fieldName == "ZINS_IA" || fieldName == "ABWZINS" || fieldName == "INFL_IA")
        {
            dataSource.Add(fieldName, 0.25);
        }
        else
        {
            dataSource.Add(fieldName, 99999);
        }
    }
    Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-DE");
    doc.MailMerge.Execute(dataSource.Keys.ToArray(), dataSource.Values.ToArray());
    doc.MailMerge.FieldMergingCallback = new HandleMergeImageFieldFromBlob();
    DataTable table = new DataTable("Signature");
    table.Columns.Add("MySignature");
    table.Rows.Add(new object[]
    {
        "MySignature2.bmp"
    });
    DataTable table1 = new DataTable("Signature1");
    table1.Columns.Add("MySignature");
    table1.Rows.Add(new object[]
    {
        "MySignature2.bmp"
    });
    doc.MailMerge.ExecuteWithRegions(table);
    doc.MailMerge.ExecuteWithRegions(table1);
    // doc.UpdateFields();
    Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
    doc.Save(string.Format("results_{0:yyyyMMddHHmmss}.doc", DateTime.Now));
    Console.WriteLine("Doc Is Saved");
    Console.ReadLine();
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
    Console.ReadLine();
}

The attachement is the template. Can anybody help me to have a look at this issue?

Thanks Alex. The another issue I forgot to mention above is when calling MailMerge.Execute() method and save with v9.8, I found in the generated report, some IF field parts are not updated automatically. I have to update them using “F9” mannually. Have you found this issue as well? This issue didn’t occur when using v9.2. But for some reasons, we have to upgrade to the higher version.

Hi Sheng,
Thanks for your request. No, unfortunately, I did not observe this issue. Your template is quite big and complex. So could you please attach a simplified document that will allow me to reproduce the problem on my side? Simply copy the IF field that is improperly updating into a new document.
Best regards,

Hi Alex,

The IF Field update issue could be deferred and the Null reference issue is more important I think. Originally, I wanted to upload a simplified document, but I encountered some strange issue: for example, a document contains 3 parts: A, B and C. When I removed part C and test report generation, the operation is successful. Then from common sense, we can determine that part C has the issue. But what is strange is when I tested part C only, the operation is still successful and the null reference exception won’t be thrown. It made me confused… So I have to upload a very large document. In fact, it is also just one part of our final template

Hi Sheng,
Thank you for additional information. Yes, I also observed the same on my side. However, I managed to simplify your document to few nested IF fields. We will let you know once the issue is resolved and we will be able to check the other issue with incorrect updating of IF fields.
Best regards,

The issues you have found earlier (filed as WORDSNET-5116) have been fixed in this .NET update and in this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.