Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Mar 06, 2019 9:59 am

After generating a document longer than 350 pages, with lot of pictures, with more than 300 TOC section lines, when calling 'UpdateTableOfContents' on Document variable, a 'System.OutOfMemoryException' exception is thrown.
Following the exception details:

Exception of type 'System.OutOfMemoryException' was thrown.
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at System.Text.StringBuilder.ToString()
at Spire.Doc.Documents.Paragraph.get_Text()
at Spire.Doc.Fields.TextRange.get_Text()
at Spire.Doc.Documents.Paragraph.ᜀ(sprᩘ A_0, Single& A_1)
at sprឣ.ᜀ(Table A_0, sprឤ A_1, Single A_2)
at sprឣ.ᜁ(Table A_0, Single A_1)
at sprឣ.ᜅ(Table A_0, Single A_1)
at sprឣ.ᜀ(RectangleF& A_0, Boolean A_1)
at sprឣ.ᜀ(RectangleF A_0)
at sprស.ᜋ(sprឞ A_0)
at sprស.ᜁ(RectangleF A_0)
at sprស.ᜋ(sprឞ A_0)
at sprស.ᜁ(RectangleF A_0)
at sprន.ᜀ(sprឌ A_0, sprឆ A_1, sprᩘ A_2)
at sprᩐ.ᜒ()
at sprᩐ.ᜓ()
at sprᩐ.ᜀ(Document A_0, TableOfContent A_1)
at Spire.Doc.Fields.TableOfContent.᜜()
at Spire.Doc.Document.UpdateTableOfContents()
at PiesseQuadro.Reporting.PriceListReport.ExecuteStep(String fileName, String format) in C:\Progetti\Adeo\Reporting\PriceListReport.vb:line 222

Checked machine memory status: there is still free memory.
Spire.Doc.dll v. 7.1.10.4041.

Thank you.
User avatar

piessequadro
 
Posts: 21
Joined: Mon Nov 05, 2018 10:53 am

Wed Mar 06, 2019 10:12 am

Hi,

Thanks for your inquiry.
Now the latest version is Spire.Doc Pack(hot fix) Version:7.2.4, I would suggest that you give the latest one a try. If the issue still happens after trying, to help us look into your case quickly and accurately, please provide your testing code and your input document (if any), also tell us your OS information (E.g. Windows 7, 64 bit, RAM:8GB) and region setting (E.g. China, Chinese). You could send them to us via email (support@e-iceblue.com). Thanks in advance.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Fri Mar 08, 2019 9:18 am

Hi.
Thank you for the answer.
Tried a couple of things, without success:
- updated Spire.Doc to 7.3.3
- removed call to 'UpdateTableOfContents' - the 'OutOfMemoryEx' is now thrown on 'SaveToFile' method (see following trace)

System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at System.IO.MemoryStream.set_Capacity(Int32 value)
at System.IO.MemoryStream.EnsureCapacity(Int32 value)
at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.Xml.XmlUtf8RawTextWriter.FlushBuffer()
at System.Xml.XmlUtf8RawTextWriter.RawText(Char* pSrcBegin, Char* pSrcEnd)
at System.Xml.XmlUtf8RawTextWriter.RawText(String s)
at System.Xml.XmlUtf8RawTextWriter.WriteStartElement(String prefix, String localName, String ns)
at System.Xml.XmlWellFormedWriter.WriteStartElement(String prefix, String localName, String ns)
at spr᪢.ᜃ(String A_0)
at spr᫽.ᜆ(String A_0)
at spr᱋.ᜀ(String A_0, Boolean A_1, Object[] A_2)
at spr᱅.ᜀ(Paragraph A_0, WordAttrCollection A_1, Boolean A_2, spr᱀ A_3, Boolean A_4)
at spr᱅.ᜀ(ParagraphFormat A_0, spr᱀ A_1)
at spr᯼.ᜀ(Paragraph A_0)
at spr᯼.ᜁ(Paragraph A_0)
at Spire.Doc.Documents.Paragraph.AcceptStart(sprᜮ visitor)
at Spire.Doc.DocumentObject.ᜃ(sprᜮ A_0)
at Spire.Doc.Documents.Paragraph.Accept(sprᜮ visitor)
at Spire.Doc.DocumentObject.ᜄ(sprᜮ A_0)
at Spire.Doc.DocumentObject.ᜃ(sprᜮ A_0)
at Spire.Doc.TableCell.Accept(sprᜮ visitor)
at Spire.Doc.DocumentObject.ᜄ(sprᜮ A_0)
at Spire.Doc.DocumentObject.ᜃ(sprᜮ A_0)
at Spire.Doc.TableRow.Accept(sprᜮ visitor)
at Spire.Doc.DocumentObject.ᜄ(sprᜮ A_0)
at Spire.Doc.DocumentObject.ᜃ(sprᜮ A_0)
at Spire.Doc.Table.Accept(sprᜮ visitor)
at Spire.Doc.DocumentObject.ᜄ(sprᜮ A_0)
at Spire.Doc.DocumentObject.ᜃ(sprᜮ A_0)
at Spire.Doc.Body.Accept(sprᜮ visitor)
at spr᯼.ᜁ(Document A_0)
at spr᯻.ᜁ()
at spr᯻.ᜄ()
at spr᯼.ᜆ()
at sprᰄ.ᜃ()
at sprᰄ.ᜀ(spr᪁ A_0)
at sprᰄ.ᜀ(Document A_0, Stream A_1)
at sprᰄ.ᜀ(Document A_0, String A_1)
at Spire.Doc.Document.ᜍ(String A_0)
at Spire.Doc.Document.SaveToFile(String fileName, FileFormat fileFormat)



Attached a smaller version of the document that has to be created (unfortunatly I cannot save a copy of the complete version due to exception).
UPDATE: sorry, it seems there is some problems attaching a file of 76MB. Is there any other way to send you the file?

Thank you.
User avatar

piessequadro
 
Posts: 21
Joined: Mon Nov 05, 2018 10:53 am

Fri Mar 08, 2019 10:37 am

Hi,

Thanks for your feedback.
Our forum has size limitation, please upload your 76MB file to Dropbox or OneDrive and then share us with the download link.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Fri Mar 08, 2019 11:05 am

User avatar

piessequadro
 
Posts: 21
Joined: Mon Nov 05, 2018 10:53 am

Mon Mar 11, 2019 3:11 am

Hi,

Thanks for your sharing and sorry for late reply as weekend.
I have noticed that your customer purchased our Standard edition. I did a test with the latest standard version (Spire.Doc for .NET Standard Edition Version:7.1), but didn't encounter the "OutOfMemoryException" when executing UpdateTableOfContents method. Is your code the same as mine? If not, please provide your testing code. And to help us further investigate your issue, please also provide your testing environment, such as system configuration (Win7/64 bit, RAM: 8GB) as well as region setting (China, Chinese). Thanks in advance.
Code: Select all
Document doc = new Document();
doc.LoadFromFile(@"sales_noprezzi_limiteprimadioutofmemory.docx");
doc.UpdateTableOfContents();
doc.SaveToFile("result.docx", FileFormat.Docx2013);

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Mon Mar 11, 2019 1:56 pm

First of all, thank you for your fast reply.
As I stated before, to generate the problem, you have to work with a bigger file size; the actual big 'example' file is near to the limit (because of the OutOfMemory exception I cannot export the complete file).
So, this morning I worked on an example that:
- load 'big' but 'no-so-big' file
- add some extra content in the same manner our application add contents

BUT: the OutOfMemory exception did not happen.
So, here comes the complete scenario: the code is executed as COM object from a non-managed environment (i.e.: Microsoft Dynamics Nav).
I tried to execute same code from both managed environment (.net console application) and unmanaged application (Dynamics Nav); only with second one the exception is thrown.
Regarding attached test solution, executing following equivalent code within unmanaged enviroment throws the error:
Dim tc As New TestClass()
tc.DoWork(".\", "c:\temp\test.docx")

Do you know any solution/workaround to this limitation?
Thank you.

p.s. Please, note that to replicate original code, I had to include a helper library (DocUtils) so the code is not so simple.
User avatar

piessequadro
 
Posts: 21
Joined: Mon Nov 05, 2018 10:53 am

Tue Mar 12, 2019 10:22 am

Hello,

Thanks for your information.
We need time to investigate and test your case in unmanaged application (Dynamics Nav). Will reply you about our testing result ASAP.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Mon Mar 18, 2019 6:51 am

Dear Robin,

We encountered many problems during the investigation since we have little knowledge about the non-managed environment (Microsoft Dynamics NAV). Therefore, we need your assistance to make our situation consistent so that we can investigate your issue quickly and precisely. Please tell us which method did you use to apply our Spire.Doc dlls in Microsoft Dynamics NAV and the equivalent code you used to execute the application. Could you please provide some screenshots that show the detailed steps? Please also provide your ExpandDocLib.tlb file. Appreciate it so much.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Mon Mar 18, 2019 8:05 am

Hello.

Attached the tlb file and some Dynamics Nav code.
I used following command to create the tlb file and register the library:
path C:\Windows\Microsoft.NET\Framework\v4.0.30319
regasm /codebase /tlb ExpandDocLib.dll

The code is very simple (C/AL) - you have to declare a global variable named 'tc' of automation type:
IF ISCLEAR(tc) THEN
CREATE(tc);
tc.DoWork ('C:\Progetti\_prototyping\TestSpireDocToc\TestOutOfMemory\bin\Debug', 'c:\temp\comtest.docx');

Please, note that you should use any unmanged environment you are familiar with (ie vb script).

Thank you.
User avatar

piessequadro
 
Posts: 21
Joined: Mon Nov 05, 2018 10:53 am

Mon Mar 18, 2019 10:46 am

Hi,

Thanks for your information. We will do further investigation.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Thu Mar 21, 2019 8:16 am

Hi,

Thanks for your patient waiting.
We don't have the custom system (Microsoft Dynamics NAV), so we cannot fully test your case with the same environment at present. Sorry for that. And as we know, the Microsoft Dynamics NAV solution is based on cloud platform which has limited memory. Hence, we guess your issue "OutOfMemory" is related to the memory size of your Microsoft Dynamics NAV system. And after parsing your large file (sales_noprezzi_limiteprimadioutofmemory.docx), we found it contains more than 1400 images, also in your code, you were adding 150 images. Handling so many pictures will certainly take up a lot of memory. After doing analysis and tests, we concluded that your code needs around 1GB memory to run. Please check if your Microsoft Dynamics NAV has enough memory to run your application. Besides, we will keep investigating. If there is any significant progress, we will let you know.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Fri Mar 29, 2019 8:43 am

Hi,

Greetings from E-iceblue.
How is your issue now? Could you please give us some feedback at your convenience? Thanks in advance.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Mon Apr 01, 2019 3:08 pm

Hi.
We were able to workaround the issue decreasing pictures size and cleaning memory as soon as the picture is inserted into the document.
We think that the best solution for this issue is to avoid passing through COM environment :D
User avatar

piessequadro
 
Posts: 21
Joined: Mon Nov 05, 2018 10:53 am

Tue Apr 02, 2019 1:24 am

Hello,

I'm delighted to hear that you have found a solution. You are so great :D
If you need further helps related to our products, just feel free to contact us.
Wish you all the best!

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.Doc