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

Free Support Forum - aspose.com

Aspose.Cells.License license error!

I call this function many times by use multi-thread for extract text from excel file.
I cannot track this error because it’s not error everytime.
How I solve this problem?


Message:
Object reference not set to an instance of an object.

Stack Trace = at ؆.㥚.㥩(Stream ԁ)
at ؆.㥚.㥩(String 㥪, Assembly 㥫)
at AO.Library.MSOffice.ExcelManager…ctor()
at Function.ConvertText(DocumentType eDocumentType, String sFilePath, AOData& oAOData, Int32& iStatusCode, Boolean bDebugMode)


Code:
//Call the class library from web service
ExcelManager _excel = new ExcelManager();


//Class that uses Aspose.Cells
public class ExcelManager{

//Constructor of the class library

public ExcelManager()
{
Aspose.Cells.License license = new Aspose.Cells.License();
license.SetLicense(_asposeLicense); <- Error at this line.
}

}

Remark: here is product info.
Product name: Aspose.Cells.dll
Assembly version: 6.0.1.0
Product version: 2011.07.20
License: Aspose.Total

Thanks,
Nuch
								</div>
								</div>

Hi,


After some investigation, we come to know that this exception might occur when multiple threads try to access the license file concurrently and this issue might be occurred infrequently during the worst case scenario.

I think, in order to resolve this type of issue, we would suggest that you avoid concurrent access to the license file. In order to make sure, you may apply Mutex as shown in the following code:

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.Cells.lic”)

mutex.ReleaseMutex()

However, if you still find this issue at your end then please try changing the license setting code as shown below (the code is in VB, you may change to C# accordingly):
e.g
'read the license file into memory stream
Dim data() As Byte = File.ReadAllBytes(“Aspose.Cells.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()

In this code, instead of passing the file path to the SetLicense method, we have read the license into the MemoryStream object and then passed that MemoryStream object to SetLicense.

Hope this works in your scenario.

Thank you.