Error with SetLicense

<!–[if gte mso 10]> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Normale Tabelle"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-fareast-language:EN-US;}

<![endif]–>

Hello together,

I could not create Excel files, because the SetLicense-Function had a problem. The License file is an Embedded Resource. I fix the problem by restart the Application Pool from the Website. Do you know this problem? Have you a solution or fix for this? We use version 5.3.1.0 of Aspose.Cells.NET.

Thanks for your help

Following problems was shown in the EventViewer:

Source array was not long enough. Check srcIndex and length, and the array's lower bounds.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Source array was not long enough. Check srcIndex and length, and the array's lower bounds.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[ArgumentException: Source array was not long enough. Check srcIndex and length, and the array's lower bounds.]

System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable) +0

System.Collections.ArrayList.set_Capacity(Int32 value) +80

System.Collections.ArrayList.EnsureCapacity(Int32 min) +34

System.Collections.ArrayList.Add(Object value) +63

ا..() +311

ا..(Stream Ԡ) +92

ا..(String , Assembly ) +139

Aspose.Cells.License.SetLicense(String licenseName) +84

ExcelInterface.Converter.AsposeImpl.ConvertToExcel(Stream outStream, Boolean asXLSX) in c:\builds\Ticontract\Live2010\code\TpesGeneral\ExcelInterface\Converter\AsposeImpl.cs:69

ExcelInterface.Converter.AsposeImpl.toXLSXStream(Stream outStream) in c:\builds\Ticontract\Live2010\code\TpesGeneral\ExcelInterface\Converter\AsposeImpl.cs:44

Export_NewGenerateExport.Page_Load(Object sender, EventArgs e) in c:\builds\Ticontract\Live2010\code\Ticontract\Website\carrier\auctions\export\NewGenerateExport.aspx.cs:137

System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14

System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35

System.Web.UI.Control.OnLoad(EventArgs e) +99

System.Web.UI.Control.LoadRecursive() +50

System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

Index was outside the bounds of the array.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[IndexOutOfRangeException: Index was outside the bounds of the array.]

System.Collections.ArrayList.Add(Object value) +31

ا..() +311

ا..(Stream Ԡ) +92

ا..(String , Assembly ) +139

Aspose.Cells.License.SetLicense(String licenseName) +84

ExcelInterface.Converter.AsposeImpl.ConvertToExcel(Stream outStream, Boolean asXLSX) in c:\builds\Ticontract\Live2010\code\TpesGeneral\ExcelInterface\Converter\AsposeImpl.cs:69

ExcelInterface.Converter.AsposeImpl.toXLSXStream(Stream outStream) in c:\builds\Ticontract\Live2010\code\TpesGeneral\ExcelInterface\Converter\AsposeImpl.cs:44

Export_NewGenerateExport.Page_Load(Object sender, EventArgs e) in c:\builds\Ticontract\Live2010\code\Ticontract\Website\carrier\auctions\export\NewGenerateExport.aspx.cs:137

System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14

System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35

System.Web.UI.Control.OnLoad(EventArgs e) +99

System.Web.UI.Control.LoadRecursive() +50

System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627



Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]

ا..(Stream Ԡ) +161

ا..(String , Assembly ) +139

Aspose.Cells.License.SetLicense(String licenseName) +84

ExcelInterface.Converter.AsposeImpl.ConvertToExcel(Stream outStream, Boolean asXLSX) in c:\builds\Ticontract\Live2010\code\TpesGeneral\ExcelInterface\Converter\AsposeImpl.cs:69

ExcelInterface.Converter.AsposeImpl.toXLSXStream(Stream outStream) in c:\builds\Ticontract\Live2010\code\TpesGeneral\ExcelInterface\Converter\AsposeImpl.cs:44

Export_NewGenerateExport.Page_Load(Object sender, EventArgs e) in c:\builds\Ticontract\Live2010\code\Ticontract\Website\carrier\auctions\export\NewGenerateExport.aspx.cs:137

System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14

System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35

System.Web.UI.Control.OnLoad(EventArgs e) +99

System.Web.UI.Control.LoadRecursive() +50

System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

Hi,

Thanks for reporting the problem.

Can you please provide us a simple sample project replicating this issue?

Also, please test your license with path from disk and see the result.

Make some folder on some drive say: c:\myfolder

Place license file there and then modify your code like this

Note: Suppose your license file name is Aspose.Total.lic so the full path to your license will be c:\myfolder\Aspose.Total.lic

[C#]


string
yourLicenseFilePath=@“c:\myfolder\Aspose.Total.lic”;

Aspose.Cells.License cellsLicense = new Aspose.Cells.License();

cellsLicense.SetLicense(yourLicenseFilePath);

If you still could not resolve it then let me know.

I am not sure, if this is the solution, because it has worked 6 weeks before. But I will try it and we will see…

Thanks for your quick answer

Hi,

Thanks. If it is not much a trouble, then try it with the latest version Aspose.Cells
for .NET v5.3.3.4
.

I am having the same issue, will you please share if there was any fix or resolution provided?

Hi Nishchalp,


We did investigate this problem a bit in the past at our end. The issue might not be related to Aspose.Cells product.
During the investigation, we noticed that this exception (e.g “Object reference not set to an instance of an object” etc.) may occur when multiple threads try to access the license file concurrently during the worst case scenario.
However, in order to resolve this issue, we would suggest that you avoid concurrent access to the license file. For example, 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:

'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()


Please try this at your end and see if it helps.

Thank you.

The solution proposed by you is not at all working. Is there anything that can be done? After introduing locking they way you mentioned, the error is still the same and as many number of times as it was earlier. The full stack is as follows:

ExportImportWorker (id=6272f9a7-089e-e211-8f0d-0050568f1a67): [Name]: ApplicationException [Message]: Cannot find license for Excel library. [Inner Exception]: Object reference not set to an instance of an object. [Stack Trace]: at XXX.AAA.Excel.Factory.ExcelFactory.CreateExcelComponent() in c:\Builds\537\XGS-SDI\XSM_510_Nightly\Sources\Libraries\Excel\Factory\ExcelFactory.cs:line 66 at XXX.AAA.Import.EngineImpl.BaseImportEngine…ctor(EngineParameterSet guids, IList rowGUIDs, IImportPolicy policy, String fileName) in c:\Builds\537\XGS-SDI\XSM_510_Nightly\Sources\Libraries\ExportImport\Import\EngineImpl\BaseImportEngine.cs:line 79 at XXX.AAA.Import.EngineImpl.AssetImportEngine…ctor(EngineParameterSet guids, IList rowIDs, IList columnsToImport, IImportPolicy policy, String fileName) in c:\Builds\537\XGS-SDI\XSM_510_Nightly\Sources\Libraries\ExportImport\Import\EngineImpl\AssetImportEngine.cs:line 52 at XXX.AAA.Import.EngineFactory.ImportEngineFactory.CreateImportEngine(Guid gridView, EngineParameterSet guids, IList rowIDs, IList columnsToImport, IImportPolicy policy, String fileName) in c:\Builds\537\XGS-SDI\XSM_510_Nightly\Sources\Libraries\ExportImport\Import\EngineFactory\ImportEngineFactory.cs:line 62 at XXX.AAA.Core.ScheduledEvents.ExportImportWorker.ProcessImport(TaskDataTransfer task, TaskDataTransferColumnMetaDataXref[] taskColumns) in c:\Builds\537\XGS-SDI\XSM_510_Nightly\Sources\Libraries\ExportImport\ScheduledEvents\ExportImportWorker.cs:line 651 at XXX.AAA.Core.ScheduledEvents.ExportImportWorker.Execute(Guid taskDataTransferID, TaskDataTransfer task) in c:\Builds\537\XGS-SDI\XSM_510_Nightly\Sources\Libraries\ExportImport\ScheduledEvents\ExportImportWorker.cs:line 512 at XXX.AAA.Core.ScheduledEvents.ExportImportWorker.ProcessDataTransfer(Guid taskDataTransferID) in c:\Builds\537\XGS-SDI\XSM_510_Nightly\Sources\Libraries\ExportImport\ScheduledEvents\ExportImportWorker.cs:line 142 ExportImportWorker (id=6272f9a7-089e-e211-8f0d-0050568f1a67): [Name]: ApplicationException [Message]: Cannot find license for Excel library. [Inner Exception]: Object reference not set to an instance of an object. [Stack Trace]: at XXX.AAA.Excel.Factory.ExcelFactory.CreateExcelComponent() in c:\Builds\537\XGS-SDI\XSM_510_Nightly\Sources\Libraries\Excel\Factory\ExcelFactory.cs:line 66 at XXX.AAA.Import.EngineImpl.BaseImportEngine…ctor(EngineParameterSet guids, IList rowGUIDs, IImportPolicy policy, String fileName) in c:\Builds\537\XGS-SDI\XSM_510_Nightly\Sources\Libraries\ExportImport\Import\EngineImpl\BaseImportEngine.cs:line 79 at XXX.AAA.Import.EngineImpl.AssetImportEngine…ctor(EngineParameterSet guids, IList rowIDs, IList columnsToImport, IImportPolicy policy, String fileName) in c:\Builds\537\XGS-SDI\XSM_510_Nightly\Sources\Libraries\ExportImport\Import\EngineImpl\AssetImportEngine.cs:line 52 at XXX.AAA.Import.EngineFactory.ImportEngineFactory.CreateImportEngine(Guid gridView, EngineParameterSet guids, IList rowIDs, IList columnsToImport, IImportPolicy policy, String fileName) in c:\Builds\537\XGS-SDI\XSM_510_Nightly\Sources\Libraries\ExportImport\Import\EngineFactory\ImportEngineFactory.cs:line 62 at XXX.AAA.Core.ScheduledEvents.ExportImportWorker.ProcessImport(TaskDataTransfer task, TaskDataTransferColumnMetaDataXref[] taskColumns) in c:\Builds\537\XGS-SDI\XSM_510_Nightly\Sources\Libraries\ExportImport\ScheduledEvents\ExportImportWorker.cs:line 651 at XXX.AAA.Core.ScheduledEvents.ExportImportWorker.Execute(Guid taskDataTransferID, TaskDataTransfer task) in c:\Builds\537\XGS-SDI\XSM_510_Nightly\Sources\Libraries\ExportImport\ScheduledEvents\ExportImportWorker.cs:line 512 at XXX.AAA.Core.ScheduledEvents.ExportImportWorker.ProcessDataTransfer(Guid taskDataTransferID) in c:\Builds\537\XGS-SDI\XSM_510_Nightly\Sources\Libraries\ExportImport\ScheduledEvents\ExportImportWorker.cs:line 142

Hi,


Thanks for your feedback.

Well, it might be due to Trust levels or IO permissions set issue on your system, see the document for your reference:
http://www.aspose.com/docs/display/cellsnet/Declaration

We highly recommend you to kindly use Full trust level permissions set if you are not using it. Also make sure that the license file there and can be accessed fine (you should have administrative rights to access the folder(s)) by your System.IO APIs dynamically), your mentioned error is referring that you do not have sufficient rights.

Let us know if it makes any difference.

If you still find the issue or could not evaluate, kindly do create a separate sample console application, zip it and post it here (do not include your license file in the zipped archive) to reproduce the issue on our end, we will check your issue soon. Without reproducing the issue on our end, we cannot help you much.


Thank you.


Thanks for your quick response. It cannot be a rights or permissions issue as it is a web app and there is one admin user that is doing it. It is successful for some sessions and some sessions fail.

Hi,


As we requested, kindly do create a separate application (preferably console application), zip it and post it here (do not include your license file in the zipped archive) to reproduce the issue on our end, we will check your issue soon. I am afraid, without reproducing the issue on our end, we cannot help you much and accurately here.

Thank you.

I will try to but just one more thing to mention that it happens when load on server is maximum but our server is capable to take that load and we do not see any other performance or speed related issues. Just this one comes when there are around 500 sessions may be accessing the excel import/export feature.

Hi,


We will wait for your sample application to reproduce the issue on our end.

By the way, for a web application, we highly recommend you to kindly place the set licensing code in a place which should be executed at least once in the whole application life cycle. For example, you may put the licensing code to some other location, e.g in global.asa file’s event, e.g Application_onstart etc (if you are not already using it). Also, if you have built your application on threaded based, this issue may happen too.

Thank you.

We actually knew this and the way application was designed ensured that it is called once per session per user before user can import or export data to or from Excel.

Hi,


We recommend you to kindly do not use Session events (e.g Session_Start etc.) as this is not reliable in worst case scenarios, please use Application events or other relevant events instead e.g Application_start may work better for it.

Thank you.

No, we are not using events like Session Start or so. We are using the constructor of the class that imports or exports. The class is loaded with the application and hence the constructor is fired once for every user session.

Hi,


Well, as you mentioned that you are using the constructor of the class that imports or exports
which seems static method that would be called for many times during worst case scenario when several users are using your web application. We request you to kindly place your licesing code at a place where the licensing code shoule be called only once per application life cycle to see if it fixes your issue.

Again, if you still find the issue after all the recommendations, please create a sample (runnable) application, zip it and post it here to reproduce the issue on our end. We will check it soon.

Thank you.