OutOfMemory Exception - AppendDocument method

Hi,

We are having out of memory exceptions while merging documents with the following sizes: 9256KB + 13KB + 16KB & 8KB.

Let me know how I can attach the documents for your reference. We are using licensed version (ver. 16.7)

Thanks,
Ashish.

@ASHPoseUser,

Thanks for your inquiry. Please try latest version of Aspose.Words for .NET 18.3. Hope this helps you.

If you still face problem, please ZIP and attach your input Word documents along with code example here for testing. We will investigate the issue on our side and provide you more information.

Hi,

Can I get a test license for the latest version? As I understand the trial version will purge the document if it is large.

Thanks,
Ashish.

I am not able to upload the zip file as the size is 7480KB and there is size limit message while uploading.

@ASHPoseUser,

If you want to test Aspose.Words without the evaluation version limitations, you can also request a 30-day Temporary License. Please refer to How to get a Temporary License?

You can ZIP the file(s), upload the ZIP file to Dropbox and share the Download link here for testing.

        SaveOptions so = SaveOptions.CreateSaveOptions(SaveFormat.Docx);
        so.TempFolder = outputFolder;
        string fullFilePath = @"D\Reports\Report1.docx";
        Document reportDocument = null;
                     //docPaths is a List<string> contains full file path
                    //the file are available throught drop box link
                    foreach (string docPath in docPaths)
                    {
                        //int index = docPaths.IndexOf(docPath);
                        if(null == reportDocument)
                            reportDocument = new Document(docPath);
                        else
                        {
                            Document temp = new Document(docPath);
                            reportDocument.AppendDocument(temp, ImportFormatMode.UseDestinationStyles);
                        }
                    }
                    reportDocument.UpdateFields();            
                    reportDocument.Save(fullFilePath, so);

Test Files: Dropbox - File Deleted - Simplify your life

Hi,

Here are another set of files which I am trying to append but getting out of memory exceptions

https://www.dropbox.com/s/p0lg91un29i5v3k/6141554.zip?dl=0

Thanks,
Ashish

@ASHPoseUser,

Thanks for sharing the documents. We are investigating this issue and will get back to you soon.

I forgot to mention that the files with names “Result_[xx].docx” are being generated with LINQ Reporting Engine.

Thanks,
Ashish.

@ASHPoseUser,

Thanks for your patience. We have tested the scenario using latest version of Aspose.Words for .NET 18.3 with following code example and have not found the shared issue. Please use Aspose.Words for .NET 18.3.

Aspose.Words.Saving.SaveOptions so = Aspose.Words.Saving.SaveOptions.CreateSaveOptions(SaveFormat.Docx);
so.TempFolder = @"c:\temp\";
Document reportDocument = null;

List<string> docPaths = new List<string>();
docPaths.Add(MyDir + "Title.docx");
docPaths.Add(MyDir + "Summary.docx");
docPaths.Add(MyDir + "Strategy.docx");

for (int i = 1; i < 10; i++)
{
    docPaths.Add(MyDir + @"6134389\6134389\Results_" + i+".docx");    
}

//docPaths is a List<string> contains full file path
//the file are available throught drop box link
foreach (string docPath in docPaths)
{
    //int index = docPaths.IndexOf(docPath);
    if (null == reportDocument)
        reportDocument = new Document(docPath);
    else
    {
        Document temp = new Document(docPath);
        reportDocument.AppendDocument(temp, ImportFormatMode.UseDestinationStyles);
    }
}
reportDocument.UpdateFields();
reportDocument.Save(MyDir + "output.docx", so);

If you are using different code example, please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing. Thanks for your cooperation.

thanks Tahir.

Did this code work with the second set of files that I shared?

Thanks,
Ashish.

https://www.dropbox.com/s/p0lg91un29i5v3k/6141554.zip?dl=0

@ASHPoseUser,

Thanks for your inquiry. We have faced System.Xml.XmlException while importing “Results_2.docx” into Aspose.Words’ DOM. We have logged this issue as WORDSNET-16603 in our issue tracking system. We will inform you via this forum thread once this issue is resolved. We apologize for your inconvenience.

Regarding memory issue, please note that performance and memory usage all depend on complexity and size of the documents you are generating.

In terms of memory, Aspose.Words does not have any limitations. If you’re loading huge Word documents into Aspose.Words’ DOM, more memory would be required. This is because during processing, the document needs to be held wholly in memory. Usually, Aspose.Words needs 10 times more memory than the original document size to build a DOM in the memory.

We suggest you please use SaveOptions.MemoryOptimization property to optimize the memory performance. Setting this option to true can significantly decrease memory consumption while saving large documents at the cost of slower saving time. Hope this helps you.

HI,

I am trying to append the following word documents:
https://www.dropbox.com/s/ig3ezgoor78e02z/Data.zip?dl=0

However I get some exceptions:

  1. System.Exception: Error while creating report section:Federal —> System.Xml.XmlException: Unexpected end of file while parsing Name has occurred. Line 1, position 536857747.
    or sometimes:
  2. System.Xml.XmlException: Unexpected end of file has occurred. The following elements are not closed: w:t, w:r, w:p, w:tc, w:tr, w:tbl, w:tc, w:tr, w:tbl, w:body, w:document. Line 3, position 134211942

Thanks,
Ashish

@ASHPose,

Thanks for your inquiry. Please share the order of files that you have used to append the documents. We will investigate the issue on our side and provide you more information.

List<string> docPaths = new List<string>();
docPaths.Add(@"Federal Summary.docx");
docPaths.Add(@"Federal Section.docx");
docPaths.Add(@"Federal Search Strategy.docx");

for (int i = 0; i < 6; i++)
{
    docPaths.Add(@"Federal Search Results"+i+".docx");
}

Here is the order:

docPaths.Add(@“Federal Section.docx”);
docPaths.Add(@“Federal Search Strategy.docx”);
docPaths.Add(@“Federal Summary.docx”);
docPaths.Add(@“Federal Search Results1.docx”);
docPaths.Add(@“Federal Search Results2.docx”);
docPaths.Add(@“Federal Design Search Strategy.docx”);
docPaths.Add(@“Federal Design Search Results1.docx”);
docPaths.Add(@“Federal Design Search Results2.docx”);
docPaths.Add(@“Federal Owner Search Strategy.docx”);

Thanks,
Ashish

@ASHPose,

Thanks for your inquiry. We have tested the scenario using following code example and faced the OutOfMemoryException. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-16612. You will be notified via this forum thread once this issue is resolved. We apologize for your inconvenience.

Aspose.Words.Saving.SaveOptions so = Aspose.Words.Saving.SaveOptions.CreateSaveOptions(SaveFormat.Docx);
so.TempFolder = @"c:\temp\";
Document reportDocument = null;

List<string> docPaths = new List<string>();
                
docPaths.Add(@"Federal Section.docx");
docPaths.Add(@"Federal Search Strategy.docx");
docPaths.Add(@"Federal Summary.docx");
docPaths.Add(@"Federal Search Results1.docx");
docPaths.Add(@"Federal Search Results2.docx");
                 
//docPaths is a List<string> contains full file path
//the file are available throught drop box link
foreach (string docPath in docPaths)
{
    //int index = docPaths.IndexOf(docPath);
    if (null == reportDocument)
        reportDocument = new Document(docPath);
    else
    {
        try
        {
            Document temp = new Document(docPath);
            reportDocument.AppendDocument(temp, ImportFormatMode.UseDestinationStyles);
        }
        catch (Exception ex)
        {


        }

    }
}
reportDocument.UpdateFields();
reportDocument.Save(MyDir + "output.docx", so);

We have not found these documents in the shared Dropbox link. Please share these documents for investigation of this issue. Thanks for your cooperation.

Here is the link:
https://www.dropbox.com/s/sx161f4m1u7y2q9/Federal.zip?dl=0

Please note that the documents can be combined in any sequence.

Thanks,
Ashish

@ASHPose,

Thanks for sharing the documents. We have managed to reproduce the System.Xml.XmlException while appending documents. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-16620. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

We are trying to open the following document:

https://www.dropbox.com/s/03hqilkk6hygsyv/Federal.docx?dl=0

using the following code:

        SaveOptions docxSaveOptions = SaveOptions.CreateSaveOptions(SaveFormat.Docx);
        docxSaveOptions.TempFolder = outputFolder;
        LoadOptions lo = new LoadOptions();
        lo.LoadFormat = LoadFormat.Docx;
        Document document = new Document(@"Path\Federal.docx", lo);
        document.UpdateFields();
        document.Save(@"Path\Federal.docx", docxSaveOptions);

We get the folllowing exception:

System.Exception: Error while creating report section:Federal —> System.OutOfMemoryException: Exception of type ‘System.OutOfMemoryException’ was thrown.
at Aspose.Words.Document.(Stream , LoadOptions )
at Aspose.Words.Document.(Stream , LoadOptions )
at Aspose.Words.Document…ctor(String fileName, LoadOptions loadOptions)
at CS.ReportEngine.Builder.FederalDocument.CreateReportSections() in D:\TFS\Production Support\ReportEngine1.0\Dev\Source\CS.ReportEngine\CS.ReportEngine.Builder\ReportSections\FederalReportSection\FederalDocument.cs:line 119
at CS.ReportEngine.Builder.ReportBuilder.BuildReport(DataBucket dataBucket) in D:\TFS\Production Support\ReportEngine1.0\Dev\Source\CS.ReportEngine\CS.ReportEngine.Builder\ReportBuilder.cs:line 45
at CS.ReportEngine.Processor.ProcessReport.ProcessSection() in D:\TFS\Production Support\ReportEngine1.0\Dev\Source\CS.ReportEngine\CS.ReportEngine.Processor\ProcessReport.cs:line 83

Thanks,
Ashish