SetLicense("Aspose.Total.lic"); Throwing occasionally error �Object reference not set to an instance of an object�

Hi,

We are using Aspose.Cells for .NET
File Version: 9.7.0.0
Product Version: 2011.02.05

We included the license file as an Embedded Resource in our BusinesLogic DLL, supporting a .net 2.0.50727.4252 web application.

We are setting the license in the following way:
var license = new License();
license.SetLicense("Aspose.Total.lic");

The web application is sitting on a Windows 2008 Server running IIS 7.0

We never had an issue in our development environment and in general it is also working in production.

The web application is running for some days/weeks without any problems on production, but we are suffering with increasing frequency an aspose issue (see unspecific error message).

With the first occurrence of the issue we were able to fix the issue by copying the license file (aspose.total.lic) to the BIN folder on production server.

The issue did not occur for a month. When the same issue reoccurred we were able to fix the issue by deleting the aspose.total.lic file from the BIN folder.

But in the last 4 business days we had to add/remove the aspose.total.lic file every day.

Restarting the web application/application pool does not help, only adding/removing the license file will help.

Error Message:

“Object reference not set to an instance of an object”

Thread information: Thread ID: 10 Thread account name: XXXXXXXXXXXXXXX Is impersonating: False Stack trace: at ?.?.?(Stream ?)

at ?.?.?(String ?, Assembly ?)

at EY.ACP.BusinessLogic.Reporting.ReportingBusinessLayer.BuildWorkbook(ReportTemplate report) in C:\GlobalTFS\...\ACP.BusinessLogic\Reporting\ReportingBusinessLayer.cs:line 86

=> line 86: license.SetLicense("Aspose.Total.lic");

Best Regards,
Thomas
Hi,

Thanks for providing us some details.

We think the issue might not be related to Aspose.Cells product. We also think this exception (e.g. "Object reference not set to an instance of an object" etc.) might occur when multiple threads try to access the license file concurrently during the worst case scenario etc. However, in order to resolve this issue, we would suggest you avoid concurrent access to the license file (if you are doing this). For example, in order to make sure, you may apply Mutex as shown in the following code:

e.g
Sample code:

[VB]
Declare Mutex variable:

Private Shared mutex As New System.Threading.Mutex()

Apply Mutex:

mutex.WaitOne()

Dim lic As New Aspose.Cells.License()
lic.SetLicense("Aspose.Total.lic")

mutex.ReleaseMutex()



However, if you still find this issue at your end for your other scenario then please try changing the license setting code as shown below for your reference:
e.g
Sample code:

'read the license file into memory stream
Dim data() As Byte = File.ReadAllBytes("Aspose.Total.lic")
Dim licenseStream As New MemoryStream(data, 0, data.Length)
licenseStream.Seek(0, SeekOrigin.Begin)

'set license
Dim lic As New Aspose.Cells.License()
lic.SetLicense(licenseStream)

'close memory stream
licenseStream.Close()



Note: Setting license is only needed once per application life cycle and should be placed at a location where it should be processed before using any other Aspose.Cells APIs, you do not need to set license multiple times or in each thread etc. You should place your licensing code in some global application level event(s), e.g you may place the licensing code in Application_start event in global.asax, so your licensing code should be processed once per application life cycle.
Please see the document on licensing for your further reference:
http://www.aspose.com/docs/display/cellsnet/Licensing


Let us know if you still find the issue.

Thank you.