Free Support Forum - aspose.com

Aspose.Cells.License.SetLicense - > Error -> Object reference not set to an instance of an object


Hi there,

We have a strange periodic error in our system.

We get an nullrefrence error sometimes when generating excel files.

I dont know what is happening, but the stacktrace is as follows:

at Aspose.Cells.x220f433da4115056.x7d0214bf69711dd9(Stream xcf18e5243f8d5fd3) at Aspose.Cells.x220f433da4115056.x7d0214bf69711dd9(String x1c1fc72fe1a3b4ea
Assembly x5807f920b6fc67c4) at Aspose.Cells.License.SetLicense(String licenseName) at Websolvens.Common.ExcelReport.getExcelReport(String LevOmr
Decimal LLEnhedId
Decimal LLSkmId
String LLSkmNavn
String SheetName
Decimal SolvensLevId1
Decimal SolvensLevId2
String _Vakd
String _Faktor1000Mk) at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md
Object[] args
Object server
Int32 methodPtr
Boolean fExecuteInContext
Object[]& outArgs) at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md
Object[] args
Object server
Int32 methodPtr
Boolean fExecuteInContext
Object[]& outArgs) at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg

I have read the following thread, and it’s kind of similar to the problem mentioned.


We have a system where users can generate excel reports. This is done by starting a asynchronous process pr excel sheet. Users can order 1 - 50 reports at a time eg. 1 - 50 processes is started.

setlicense is called once for each process. this ok?

Hope you can help.

Anders




Hi Anders,

Please
make sure you set license only once per application/project. Maybe you
should set license on ApplicationStart event if you are using the product a in web scenario or at some place before your application winform or application process should start, see the document:
here:http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/licensing.html


<o:p>Do you implement multi-threading in your project, Could you give us more details, OS, environment information, .NET framework, any other etc. And, in which sequence issue occurs most likely? </o:p>We will also analyze your issue further and get back to you soon.

<o:p>
</o:p>

<o:p>Thank you.
</o:p>



Hi Amjad!

First of all thanks for the quick response!

I have searched the hole web application and found that we are setting the license file in many places in our code. Example: each time the user request a excel sheet generated, the SetLicense is called. And the generation is done multi-threaded.

Could this be the reason for the error?

I have moved the SetLicense to only be in the application start method. Will it be sufficient to have it only once there?

We run winserver 2003, .NET 2.?

Or in other word: Is the calling of setLicense many, many times a probable reason for getting this error?

Thanks again

Hi,

"I have moved the SetLicense to only be in the application start method. Will it be sufficient to have it only once there? "

Yes, it would be fine per one application/project.

"Or in other word: Is the calling of setLicense many, many times a probable reason for getting this error?"

It should not be any problem calling the set License code multiple times in a project/application but, it requires to be called only once per application life cycle.


Also, I would like to comment regarding multi-threading, you might be knowing all this already. Aspose.Cells for .NET library is written in managed C#.NET, so, concurrency and multithreading is not a problem by any means. Aspose.Cells for .NET does support Multithreading and you may create multi-threaded applications using Aspose.Cells. However, you need to note the following details in this regard.

For your info, to save memory, there is a global shared string table in an Excel file. So if you change a single workbook data concurrently in multi-threads, the result may be unstable. There is also a global section in an Excel file which contains global information of drawing objects and other information. So, if you want to change the objects settings concurrently in multi-threads, the result might be unstable too. It is to be noted here this is a limitation of MS Excel formats and nothing to do with Aspose.Cells for .NET. So, the best way to utilize multi-threading is to create separate Workbook objects in each thread. Your application can handle multi-workbooks at the same time but please don’t handle a single Excel file in multi-threads. And, I hope your current application is doing what should be better in a multi-threads.

Have a good day!


Thank you.