Free Support Forum -

Setting the license

Hi - we are running a service on a Windows 2012 R2 platform written in C#. It uses Aspose.Total.

We create 40 background processes to manage our tasks (for example, rasterizing PDFs to images). We set the licence for Aspose.Pdf once per background task using the following code:

var l = new Aspose.Pdf.License();
l.SetLicense(new MemoryStream(Encoding.UTF8.GetBytes(NSLegalConstants.AsposeTotalLicenseString)));

where NSLegalConstants.AsposeTotalLicenseString contains a string copy of our licence.

This works well nearly all the time. However, sometimes it fails and we end up with “Evaluation Copy” printed on our rasterized images. It seems to fail if the calls to SetLicense happen fast (i.e. 20 within a second).

Any thoughts on this? Should we be setting the licence for each background thread (we are using BackgroundWorker to create the threads)? Is there a better and more reliable way to set the license?

Hi Paul,

Thanks for your inquiry. I am afraid there is no time limitation on license setting. We will appreciate it if you please share some console application to replicate it at our end, then we can guide you exactly.

Moreover, you may try using license as embedded resource and share the results.

We are sorry for the inconvenience caused.

Best Regards,

Hi Paul,

Adding more to Tilal’s comments, 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.

PS, when using a multi-threaded application, you do not need to initialize the license in every attempt as the license remains validated through out application life cycle.