Hello,
As said in the title, sometimes DocumentBuilder.CurrentSection is null when my program is running normally.
However, if i slow down the execution (by saving regularly the document into a new file, not into the source file) then this issue doesn’t happen and my program can keep running as intended.
Since i have no clue on why this problem happens, how can i solve this ?
Sincerely.
@guyyyyyyyyyyy Could you please create a simple console application that will allow us to reproduce the problem on our side? We will check the issue and provide you more information.
The project and use case is too complexe to make a simple application, however i have solved this issue by calling Document.UpdatePageLayout each time i insert a buiding block (wich happens a lot).
Nonetheless calling this method systematically seems a bit heavy, is there a proper way to do it ?
@guyyyyyyyyyyy Calling Document.UpdatePageLayout
method forces Aspose.Words to rebuild document layout, this is quite resource consuming operation. So it is not recommended to call this method multiple times is not recommended since this might have a significant memory consumption and performance impact.
Unfortunately, it is difficult to say what causes the problem without ability to reproduce it in our side. Instead of calling Document.UpdatePageLayout
you can try using the following code:
// Save open the document to force Aspose.Words to validate document.
using (MemoryStream ms = new MemoryStream())
{
doc.Save(ms, SaveFormat.Docx);
ms.Position = 0;
doc = new Document(ms);
}
Usually saving document to flow formats, such as DOCX, is faster than building document layout.
1 Like
Thank you, it is indeed faster but once the document is reloaded, my cursor is not at the correct position anymore.
How do i solve this ?
@guyyyyyyyyyyy Please try saving the document without reloading it:
// Save the document to force Aspose.Words to validate document.
using (MemoryStream ms = new MemoryStream())
{
doc.Save(ms, SaveFormat.Docx);
}
Document validation process is performed before saving the document.
Of course it would be better to reproduce the problem on our side to determine what actually cause the problem on your side.
1 Like