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

Free Support Forum - aspose.com

Is there any harm setting aspose license multiple times?

We have a method that creates PDF document using Aspose.Pdf. We are randomly getting this error At most 4 elements (for any collection) can be viewed in evaluation mode even though we are using valid paid license. I have already created a post here here without receiving any satisfactory answer.
Currently we set the aspose license at the application start ( ASP.NET Web API)

[assembly: OwinStartup(typeof(MyNamespace.Api.Startup))]

namespace MyNamespace.Api
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {            
            LicensesConfig.RegisterAsposeLicenses();
            // other stuff
	    }
	}
}



    public class LicensesConfig
    {
        public static void RegisterAsposeLicenses()
        {
            var path = ConfigurationManager.AppSettings["aspose:license-filepath"];
            if (File.Exists(path))
            {
                using (Stream licStream = new FileStream(path, FileMode.Open))
                {
                    // set aspose cell license
                    licStream.Seek(0L, SeekOrigin.Begin);
                    Aspose.Cells.License cellLicense = new Aspose.Cells.License();
                    cellLicense.SetLicense(licStream);

                    // set aspose pdf license
                    licStream.Seek(0L, SeekOrigin.Begin);
                    Aspose.Pdf.License pdfLicense = new Aspose.Pdf.License();
                    pdfLicense.SetLicense(licStream);

                    // set aspose barcode license
                    licStream.Seek(0L, SeekOrigin.Begin);
                    Aspose.BarCode.License barcodeLicense = new Aspose.BarCode.License();
                    barcodeLicense.SetLicense(licStream);

                    // set aspose OCR license
                    licStream.Seek(0L, SeekOrigin.Begin);
                    Aspose.OCR.License ocrLicense = new Aspose.OCR.License();
                    ocrLicense.SetLicense(licStream);
                }
            }
        }
    }

The method that creates the PDF document is being called concurrently using Hangfire background task, so we can create multiple PDF document concurrently. (Max 20 concurrent jobs)
To get rid of evaluation mode error I am thinking of registering Aspose license again at the beginning of this method.

public void CreateDocument()
{
       LicensesConfig.RegisterAsposeLicenses();

      // Document manipulation using Aspose.Pdf
}

Questions
1> Since create document method will be executed in multiple threads concurrently is there any harm setting license multiple times?
2>Is there anyway to check if license is already set, and if not then set it?

Note that license file does exist at the configured path and license does get apply on application start, otherwise we would have gotten evaluation copy water mark on ALL the pdfs, cells documents that we create.

@

There is no issue in terms of using this as this call is not that much costly in terms of executing. You need to call the license for every thread in your application.

There is no such available in versions that have been released after July 2020 last year. Earlier, we used to have a property License.IsLicensed available that use to tell the license status. But this was removed from API owing to security reasons. For now, you can check the license call in try/catch block and in case there is any exception, you would get to know that there is some issue in loading license.