We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose.Pdf.Document Save Null exception on heavy load

Under heavy load sometimes the Save(Stream outputStream, SaveOptions options) method throws a null exception.

I am unable to reproduce this consistently however, it does happen occasional when there is many concurrent conversions are happening at the same time.

Unfortunately the stack trace does not help much since the dlls are obfuscated.

at ​.(Stream )
at ​.()
at .()
at .(Document , Stream , DocSaveOptions )
at Aspose.Pdf.Document.(Stream , SaveOptions )
at Aspose.Pdf.Document.Save(Stream outputStream, SaveOptions options)

Calling code:

            using (var tmpStream = new MemoryStream())
			{                   
               var tmpDoc = new Document(inputStream, true);
                
				if (tmpDoc.Pages.Count > pageLimit)
                {
                    tmpDoc = TruncatePDFDocument(tmpDoc, pageLimit);
                }


                tmpDoc.Optimize();
                tmpDoc.OptimizeResources(new Document.OptimizationOptions {
                    LinkDuplcateStreams = true,
                    RemoveUnusedObjects = true,
                    RemoveUnusedStreams = true,
                });

                try
                {
                    tmpDoc.RemoveMetadata();
                    tmpDoc.Save(tmpStream, new DocSaveOptions()
                    {
                        Format = DocSaveOptions.DocFormat.DocX,
                        Mode = DocSaveOptions.RecognitionMode.Textbox
                    });

                    tmpDoc.FreeMemory();
                    tmpDoc.Dispose();
                }
                catch(Exception e)
                {
                    _log.Error(e.Message);
                }







                var result = ConvertWordToSVG(tmpStream, pageLimit, true);
                if(result == null)
                {
                    _log.Error($"Failed PDF conversion, fallback to text.");
                    result = ConvertWordToSVG(tmpStream, pageLimit, false);
                }

                return result;
			}

@psvitz

Thank you for contacting support.

We are unable to compile the code snippet shared by you as it includes some undefined methods and variables. Would you please create a sample application along with source files reproducing this issue so that we may try to reproduce and investigate it in our environment. Also, elaborate heavy load scenario for our reference.