Object reference not set to an instance of an object. Generating table

Hi,

Just started to test 11.10.0 and found the following error:

{"Object reference not set to an instance of an object."}
_HResult: -2147467261
_message: "Object reference not set to an instance of an object."
Data: {System.Collections.ListDictionaryInternal}
HelpLink: Nothing
HResult: -2147467261
InnerException: Nothing
IsTransient: False
Message: "Object reference not set to an instance of an object."
Source: "Aspose.Words"
StackTrace: " at Aspose.Words.DocumentBuilder.get_CurrentStory() at Aspose.Words.DocumentBuilder.get_CurrentSection() at Aspose.Words.DocumentBuilder.get_PageSetup()"
TargetSite: {Aspose.Words.Story get_CurrentStory()}

This software has been working for a long time. Not sure where to start looking for the problem.

This appears to be the initial error that started the sequence:

at Aspose.Words.DocumentBuilder.x87c38d4df0b94981()
at x28925c9b27b37a46.x8e63dd35709cb9ab.xcbc713eb2e22657d()
at Aspose.Words.DocumentBuilder.InsertCell()
at ChangeAide.clsWRD_AsposeWord.Table_Insert_InfoMap(clsFG_EditPage& robjEPG, clsFG_Row& robjCurRow) in D:\Projects\ChangeAide\clsWRD_AsposeWord.vb:line 83

I’ll be glad to investigate further … what should I look for?

Regards, Bruce

Hi Bruce,

Thanks for your inquiry. Could you please attach your input Word document (.doc/.rtf file) and code here for testing? I will investigate the issue on my side and provide you more information.

Best regards,

Hi,

I have isolated the problem to removing a paragraph inside a cell. The next InsertCell following the paragraph removal causes the fault. This now leaves an extra line in the cell. This was working fine prior to this last release.

I will now see if I can create a test routine to demonstrate the problem. (or find another way to remove the paragraph).

Regards, Bruce

Hi Bruce,

Thanks for your inquiry. Sure, we will wait for your input on this. We will gladly look into fixing your problem as soon as we can reproduce it on our side.

Best regards,

Hi,

I thought the problem may have been fixed with the latest release. The problem still exists. I have now produced a small set of code that creates the problem. Please confirm that you can recreate the problem.

This code did work prior to 11.10.0.

I am using the doc builder to create a table … and eliminate any blank lines at the end of the cell.

With mbldDOC
    .StartTable()
    For plngRow = 1 To 10
        pblnError = False
        Try
            .InsertCell()
        Catch ex As Exception
            Trace.WriteLine(ex.Message)
            pblnError = True
        End Try
        If pblnError = False Then
            .Write("this is col 1")
            pcellToUse = .InsertCell()
            If plngRow = 7 Then
                .InsertHtml(pstrHTML) 'this causes an error as inserts an extra blank line
            Else
                .Write(pstrHTML)
                .InsertParagraph() 'this causes an error when removed.
            End If
            'check for any extra paragraphs
            If pcellToUse IsNot Nothing Then
                With pcellToUse
                    If .ChildNodes.Count > 1 Then
                        If .LastParagraph.IsEndOfCell = True Then
                            If .LastParagraph.Runs.Count = 0 Then
                                'if this statement is not executed, no error will occur …
                                ' however, an extra blank line will exist.
                                .LastParagraph.Remove()
                                'this statement causes the error to occur.
                            End If
                        End If
                    End If
                End With
            End If
        End If
        .EndRow()
    Next
    .EndTable()
End With

The failure starts when .LastParagraph.Remove() is executed.
The failure actually occurs when the next .InsertCell occurs.

If .LastParagraph.Remove() is not executed, the routine works fine.

I’ve attached a routine from my class module which you can try.

Regards, Bruce

Hi Bruce,

Thanks for the additional information. While using the latest version of Aspose.Words i.e. v11.11.0, I was unable to reproduce this exception on my side. Could you please double check if you are using the latest version (11.11.0) on your side? You can dynamically check if you’re referencing the correct DLL by using the following code snippet:

System.Reflection.Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (System.Reflection.Assembly assembly in assemblies)
{
    System.Reflection.AssemblyName assemblyName = assembly.GetName();
    if (assemblyName.Name.Contains("Aspose.Words"))
        Console.WriteLine("Aspose.Words Version Number: " + assemblyName.Version.ToString());
}

Moreover, I have attached the Word document (out.docx), i.e. generated on my side, here for your reference.

If we can help you with anything else, please feel free to ask.

Best regards,

Hi,

I am definitely using 11.11.0… This code started failing with 11.10.0. (as above).

And if you look closely at the sample, you will see that the sample actually is failing. The output should have been a two column table. The first row works and the remainder are only one column wide. Thanks for providing the out.docx that confirms the failure.

I put a ‘try catch’ routine around the area that creates the fault. Take some time to trace the flow of the code and I expect you will see the error the second time the ‘InsertCell’ is executed.

or remove the Try Catch around the first ‘InsertCell’ you will see the error … or comment out the line: “.LastParagraph.Remove()” the full table will appear (the fault does not occur).

I’ve included this test routine in my full application so I needed to make sure that the test code completed successfully. (thus the use of trace rather than allowing the error to fill up the error log).

Regards, Bruce

Hi Bruce,

Thanks for the additional information. I managed to reproduce this exception on my side. I have logged this issue in our bug tracking system. The issue ID is WORDSNET-7578. Your request has also been linked to this issue and you will be notified as soon as it is resolved. Sorry for the inconvenience.

Best regards,

Hi Bruce,

Thanks for your patience. It is to update you that our development team has finished analyzing your issue and has come to a conclusion that is your issue and the behaviour you’re observing is actually not a bug in Aspose.Words. Considering the following code snippet, when builder.InsertParagraph(); statement is executed, the current position of builder will be moved to this newly created paragraph. When this paragraph is removed, the current position of builder will be null (because the paragraph no longer exists). So, to avoid the NullReferenceException on the next step, please move the cursor using DocumentBuilder to the last paragraph of the cell or any other paragraph in the document.

DocumentBuilder builder = new DocumentBuilder();
builder.StartTable();
Cell cell = builder.InsertCell();
builder.InsertParagraph();
cell.LastParagraph.Remove();
// Move builder to the last paragraph of the cell.
builder.MoveTo(cell.LastParagraph);
builder.InsertCell();

Please let me know if I can be of any further assistance.

Best regards,