StackOverFlow exception processing PDFs

We have a Scrub client that frequently receives various memory exception errors when our product removes metadata from PDFs. Mostly occurs with PDFs but sometimes Word files. It can happen on small PDFs as well as larger ones. Processing stops, it locks up Outlook and our logging reports “trying to continue via Console component”. We have had the client try several builds of Scrub that included older version of Aspose and the issue continues. The current versions we have in our product, and they have tested, are:



Aspose.Pdf.dll 17.1.0.0

Aspose.Words.dll 17.2.0.0

Aspose.Cells.dll 17.2.0.0

Aspose.Slides.dll 15.5.0.0



This is the code that is causing the StackOverFlow exception.



public static void SetLicenses()

{

if(!Set)

{

Set = true;

try

{

CellsLicense.SetLicense(new MemoryStream(Properties.Resources.Aspose_Cells));

PdfLicense.SetLicense(new MemoryStream(Properties.Resources.Aspose_Pdf));

WordsLicense.SetLicense(new MemoryStream(Properties.Resources.Aspose_Words));

SlidesLicense.SetLicense(new MemoryStream(Properties.Resources.Aspose_Slides));

}

catch { Set = false; }

}

}



Any insight on what or why this might be causing the memory error?



All the license files are resources of the DLL responsible for setting the licenses for the application.



Thanks,

Kristen Theologus

Scrub Support Specialist

Hi Kristen,


Thank you for contacting support. We have released the latest version 17.4.0 of Aspose.Pdf for .NET API. Kindly download and try the latest version of each Aspose API. However, if this does not resolve the error, then please prepare a simple application which reproduces this error in your working environment and send us its zip archive for the testing purposes. We shall investigate and reply you appropriately. Please also refer to these helping links: Download Aspose APIs and Send Confidential Files to Aspose Staff

Are there any builds notes for what you have changed in the 17.4 Aspose.pdf?

This is not something that is reproducible on demand and you are asking us to blindly throw another driver version at our client who has been struggling with this issue for a year.

We’d like a little more explanation of what could be causing the StackOverFlow exception error.

Thanks,
Kristen

Hi Kristen,

Thanks for contacting support.

As per your initial post, the code snippet which you have shared is related to license initialization for API's which you are using in your project. However as per problem description, you are facing problem while removing Metadata information for some PDF documents. So in order for us to figure out the actual reasons behind this problem, as requested by Imran, please create a small application along with input PDF files causing this problem, so that we can test the scenario in our environment. We will test the scenario and will keep you updated with our findings. We are really sorry for this inconvenience.

Please visit the following link for information related to Release Notes of Aspose.Pdf for .NET 17.4.0.

Allow me to clarify. (1) This is NOT reproducible (2) it has only occurred at our client site; never in our test environments and (3) occurs randomly regardless of the PDF.

Therefore, I’m confused as to how I can provide what you request. Our developer reports the exception is thrown at the time we set the license info which is why that snippet of code was provided. I guess I can assume we are setting the license correctly? He had hoped that you could provide some guidance around the error in general. It appears that the process of removing metadata from the PDF does not even begin when this error appears.

Thanks.

Hi Kristen,


Thank you for the inquiry. Normally, StackOverFlow error occurs when a program tries to consume more memory than the actual allocated memory (or in the similar scenarios). It is difficult for us to let you know about the cause of this error because it depends on the implementation of custom application.

Your client may be using custom classes to apply the license in the code, because there is no PdfLicense class in the Aspose.Pdf API. Each Aspose API offers a License class and developers can apply the license by calling its SetLicense method. In that way, your license code appears fine. There are various ways to apply an Aspose license. Please also refer to this help topic: Apply License to Aspose.Pdf for .NET API

PS: It is not possible for us to track the real cause without replicating this error in our working environment. Once the error is replicated in our working environment, then we would be able to fix it.
KTechnogal:
Allow me to clarify. (1) This is NOT reproducible (2) it has only occurred at our client site; never in our test environments and (3) occurs randomly regardless of the PDF.

Therefore, I’m confused as to how I can provide what you request. Our developer reports the exception is thrown at the time we set the license info which is why that snippet of code was provided. I guess I can assume we are setting the license correctly? He had hoped that you could provide some guidance around the error in general. It appears that the process of removing metadata from the PDF does not even begin when this error appears.

Thanks.

Hi Kristen,

Thanks for sharing the details.

Adding more to Imran’s comments, as per my understanding from above description, the issue which your client is facing is intermittent and its not reproducible consistently. Furthermore, if the license was not properly being initialized, you may have encountered issue on every attempt which does not seem to be the case. However in order for us to identify the actual reasons behind this problem, we need to first replicate the issue in our environment. So as requested earlier, can you please create a small application which can help us in reproducing it (we do understand that sharing the whole production application may not be possible, but any sample application with identical implementation can help us in testing the scenario).

Please note that when using Stream object, the problems might occur because the license file will be locked by one instance and other instance of Stream will try to read/load its contents.

Please note that Aspose.Pdf initializes the license when first instance/object of Aspose.Pdf for .NET is created and its recommended to place the license initialization code n some static method which is executed once at that start of application. There is no need to re-initialize the license in multi-threaded environment when a new thread is created. The license is valid until the main application thread is running.

May be you can place the license initialization code in Main(), Page_Load() or any method which is executed at the start of application.

We are sorry for your inconvenience.