Sporadic problem with SetLicense

Hello,

I have licenses for Aspose .Words and .PDF.Kit. They are used in a web application that produces documents and then mails them.

Occasionally, the documents will contain the evaluation message. This occurs in approximately 5 to 10 percent of documents. As far as I have observed, when this happens the evaluation message for both products is present.

The SetLicense routine is called each time a set of documents is created.

I have code to trap any errors that occur while calling SetLicense, and so far I have not found an error. I tested the code by deliberately generating an error

SetLicense("BadFileName.lic")

and this error did get trapped in my code.

Thanks for any information you can provide about this problem.

Randy

Hi Randy,

Thanks for your inquiry.

There are a handful of customers who have been affected by this sort of issue in the past. We have never been able to reproduce the issue on our side so we have been unable to look into it further. What is in common in all cases is that the license is being set concurrently many times in the application. This is not how the license system was designed to be used, the license should be set once before using the Aspose class per application domain.

We highly suggest you to consider moving the license call to a method which fires only once before any Aspose product is used. If you really can't change the way you are setting the license right now, it would be recommended to instead load the license into a stream once at startup and then apply the license from stream with each customer request. This has avoided this issue with customers in the past.

If you are worried about the evaluation message being added, you can implement your own checking method by exporting an empty document object to stream in .txt format and then reading it back with StreamReader for any matching evaluation text.

If you have any further queries, please feel free to ask.

Thanks,

Hi Adam,

Thanks for responding.

I have set my Aspose components to run the setlicense when the user logs on and only then.

However, I still have the issue of the evaluation message printing occasionally in documents. What I have found is that an error in my program appears to cause the Aspose components to go into "evaluation mode". Here is how it happens:

This line of code will throw a null reference exception roughly one time out of every fifteen times that I generate documents.

Document.Range.Bookmarks(BookmarkName).Text = ""

Why this error occurs, I do not know yet. When it does, after that every document generated by the user will contain the evaluation message, until the user logs out and back in.

Can you suggest any cause or resolution for this (not my error, but why the evaluation message would appear after it)?

Also, is there a simple way to determine at runtime if the Aspose components have been successfully licensed? You mentioned creating an empty document and looking for the evaluation message. This will work but sure seems cumbersome, is there not an easier way (like a function or property call that would return this status)?

Thank You,

Randy Craven

Hi Randy,

Thanks for this additional information.

There is no direct reason as why an exception in the Range class would cause Aspose.Words to work in evaluation mode, unless you are setting the license in the same try block after the Range line of code. That of course does not make sense as you are most likely setting the license way before that line.

Are you able to attach one of the documents and the name of the bookmark which is causing this problem? I will look into further for you.

I'm afraid the technique described is the only way to test if the component is running in evaluation mode or not. We don't provide a build in method which returns if an Aspose component is licensed or not for security reasons.

Thanks,

Hi Adam,

Here is some additional information. The null reference exception is not causing the Aspose component to go into evaluation mode, it appears to be the reverse. Let me explain:

The code is using the Range.Replace function to clear an unneeded block of text from the document, by setting the bookmark text to an empty string. The code opens an input document which is a template, does the replace functions, then saves the document to a target path.

I trapped the null reference exception when attempting to set the bookmark text. The reason the bookmark was not found is that my input document contained the evaluation message and has been truncated. The target bookmark was truncated from the document and this produces the error. The actual template file does not contain the evaluation text, it would appear that when the document is opened the evaluation message was added at that time.

So, the Aspose component appears to have gone into evaluation mode prior to opening my template document.

As I mentioned, this error only occurs sporadically, in the most recent case I had to run the process that generates these documents 25 times to get the error. 12 to 18 times is more typical.

Do you have any ideas why this might be happeng? In the meantime, I will write some code to test an empty document each time and run the SetLicence again if the evaluation message is found.

Thanks,

Randy

Hi Randy,

Thanks for this additional information.

Yes this makes more sense, the license was not set from the beginning and instead was the cause of the exception with the bookmark.

Do the users share the same application domain and possibly that two users are logging at the same time? Also did you try loading the license from a single instance of a global stream instead of from the disk?

Thanks,