Temporary SetLicense failure

Long running application, Aspose.PDF 17.1
Today, at one site, SetLicense (from embedded resource) failed

08:30:27.23: GetFileImage RoutedContent/6853b630-a692-42fa-946c-c12895ec50fe/5350a502-ee43-41ce-a706-4528f644b6ea/8ca4e5e4-2e9a-4990-8617-d833be76e9bd f=1234deb1-ed20-49d6-b42a-0cc7d76101a6 R1 of 1; Pending False; HavePDF False; size 2356077
08:30:27.25: AsposePDFLLicense - System.NullReferenceException: Object reference not set to an instance of an object.
at .[1](Stream [1])
at .[1](String [1], Assembly


)
at Aspose.Pdf.License.SetLicense(String licenseName)
at Spitfire.sfPMS.DocContent.sfAsposePDFLink.AsposePDFLLicense()

The error repeats in our log every time we try and create a PDF, so this was not a one off.

The code of the method:

Public Shared Function AsposePDFLLicense() As Aspose.Pdf.License
Dim pdfLicense As Aspose.Pdf.License = New Aspose.Pdf.License
Try
pdfLicense.Embedded = True
pdfLicense.SetLicense(“Aspose.Total.lic”)
Catch lx As Exception
System.Diagnostics.Trace.WriteLine(String.Format("{0}: {1} - {2} ", Now.ToString(UtilityToolkit.Sys.TraceTimeFormat), System.Reflection.MethodInfo.GetCurrentMethod.Name, lx.ToString))
End Try
Return pdfLicense
End Function

To emphasize: the code has not changed, the version of ASPOSE.PDF has not changed, the IIS server has not changed, the license file has not changed.

Seems a bit similar to Urgent: Aspose License stopped working

Based on that thread, I restarted the IIS APP Pool and the issue has resolved.

Guess what: the client wants to know WHY and if it will happen again?
Any guidance you can provide?

@syork.spitfiremanage

Thank you for contacting support.

We would like to share with you that a NullReferenceException can occur if: A local variable or member field is declared but not initialized. Due to some variables and memory mapping in your system, probably a NULL value was assigned to the variable pdfLicense which was declared but not initialized. Same exception can be reproduced by using below code snippet:

Public Shared Function AsposePDFLLicense() As Aspose.Pdf.License
    Dim pdfLicense As Aspose.Pdf.License = New Aspose.Pdf.License
    pdfLicense = Nothing
    Try
        pdfLicense.Embedded = True
        pdfLicense.SetLicense("Aspose.Total.lic")
    Catch lx As Exception
        System.Diagnostics.Trace.WriteLine(String.Format("{0}: {1} - {2} ", Now.ToString(UtilityToolkit.Sys.TraceTimeFormat), System.Reflection.MethodInfo.GetCurrentMethod.Name, lx.ToString))
    End Try
    Return pdfLicense
End Function

We have logged an investigation ticket with ID PDFNET-44714 in our issue management system to investigate and devise a way out, to ensure this does not occur again in your environment. We will share our findings with you as soon as the ticket will be investigated. We are sorry for the inconvenience.

Thanks for the laugh. I’ve been programming for 30+ years and know what a NullReferenceException is. But you couldn’t know that. I can also read a stack trace and see the exception is in your code.

I can also read the DIM statement and see it sets the object reference

Dim pdfLicense As Aspose.Pdf.License = New Aspose.Pdf.License

So. Given code that has been working for MONTHS on an IIS server that is unchanged for MONTHS, what environmental situation would cause your code to get a NullReferenceException instead of loading the license?

@syork.spitfiremanage

We would like to share with you that we were trying to explain the possible reason for the exception, answering “WHY” part of your inquiry. However, we apologize if that sound unpleasant to you.

Moreover, the problem lies with declaring and initializing of variable, that is out of scope for Aspose.PDF API. You may follow up over Microsoft Forums to track if some kind of Recycling routine or any other routine of IIS Server can cause such a problem. On our part, we will let you know about initializing the variable of License Class while declaring it so that this issue can be avoided for future references. We will be updating you as soon as the ticket is investigated in our environment.