we are getting object reference not set to an instance of object when performing setLicense ocassinally in Aspose.cells. This does not happen all the time but ocassionally and if that happens, all subsquent request gets the same error. here is the code that gets this error.
protected virtual void SetLicense()
{
Aspose.Cells.License license = new Aspose.Cells.License();
if (!string.IsNullOrEmpty(ConfigurationSettings.AppSettings["LicenseFile"]))
{
license.SetLicense(ConfigurationSettings.AppSettings["LicenseFile"]);
}
}
The line of code getting this error is
license.SetLicense(ConfigurationSettings.AppSettings["LicenseFile"]);
Can you please let us know the reason why sometimes this gets this error. The only way we get rid of this problem when this happens is to, restart IIS and then it starts working. Your feedback is appreciated
Thanks
Hi,
You should call License.SetLicense from the Global.asax.cs (Global.asax.vb) file, in the Application_Start protected method.
Follow these simple rules:
· The license only needs to be set once per application domain.
· You need to set the license before using any other Aspose.Cells classes.
Calling License.SetLicense multiple times is not harmful, but simply wastes processor time.
If you are developing a Windows Forms or Console Application, call License.SetLicense in your startup code, before using Aspose.Cells classes.
When developing an ASP.NET application, you can call License.SetLicense from the Global.asax.cs (Global.asax.vb) file, in the Application_Start protected method. It is called once when the application starts. Do not call License.SetLicense from within Page_Load methods since it means the license will be loaded every time a web page is loaded.
If you are developing a class library, you can call License.SetLicense from a static constructor of your class that uses Aspose.Cells. The static constructor will execute before an instance of your class is created making sure Aspose.Cells license is properly set.