Aspose.SetLicense method throws System.IndexOutOfRangeException in rare occassion

Hi There,

We are using multiple flavors of aspose (Cells, Email, PDF, Doc) and one of them is Aspose.PDF. We are using Aspose in class library. We recently encountered following exception (Over the course of last 10 years, this may be 6th time SetLicense caused grief):
Type of exception: System.IndexOutOfRangeException
Exception level [2] Msg [Index was outside the bounds of the array.] Stack trace below:

at #=zmfM8xsCSe5YjPDyB_uPtsZY=.#=z3CFKlUIlooq_(Stream #=zIm3CH5M=)
at #=zmfM8xsCSe5YjPDyB_uPtsZY=.#=z3CFKlUIlooq_(String #=z4d$uoQg=, Assembly #=z6xtCVOI=)
at Aspose.Pdf.License.SetLicense(String licenseName)

Issue was automatically resolved when windows service was restarted.

We have been setting license in class constructors, where library is used;

We are not sure of the cause for this exception. I have looked in different other posts related to SetLicense and the most common official suggestion I found was, to SetLicense in “Static Constructor”

If setting license in static constructor is correct way for PDF, does it apply to other flavors of Aspose as well?

Looking forward to resolution,

Cheers, Bhavin


This Topic is created by asad.ali using Email to Topic tool.

@james.simpson,

I like to inform that recommended practices are same for all APIs in order to set license.

• If you are developing an ASP.NET application, you can call License.SetLicense from the Global.asax.cs (Global.asax.vb) file, in the Application_Start protected method. It is called once when the application starts. Do not call License.SetLicense from within Page_Load methods since it means the license will be loaded every time a web page is loaded.

• If you are developing a Windows Forms or console application, call License.SetLicense in your startup code, before using Aspose.Pdf for .NET classes.

• If you are developing a class library, you can call License.SetLicense from a static constructor of your class that uses Aspose.Pdf for .NET. The static constructor will execute before an instance of your class is created making sure Aspose.PDF for .NET license is properly set.

• in case of WCF service, depending upon its hosting:
- if it is custom ServiceHost - then you can set license in service host start event
- if it is IIS - then set license can be called in Global.asax

Hi @Adnan.Ahmad

Thank you for your reply,

Cheers, Bhavin

@james.simpson,

Your welcome.