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

Free Support Forum - aspose.com

Call License.SetLicense once from Global.asax.cs File in Application_Start Method

Hi,

We are getting the following server error intermittently on our production servers. This happens when we try to set the license. Now, ours is a HTTP handler class library and we set the license in the “Process Request” method, meaning, it will call the set license for every request (multiple times).
The error goes away after we touch the Web.Config file. Our production is a load balanced clustered environment.However, it’ll come back after a period of time. Can you please help us root cause and fix this permanently? We are using Aspose.Words.dll(6.0.0.0) and Aspose.Slides.dll(2.9.2.0)

Here is the stack trace:

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.]
ly.a(Stream A_0) +266
ly.c(String A_0, Assembly A_1) +233
WebDAVServer.SqlStorage.WebDAVHandler.SetAsposeLicense(HttpContext context) +442
WebDAVServer.SqlStorage.WebDAVHandler.ProcessRequest(HttpContext context) +247
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +598
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +170

Hi Bin,

Thanks for your inquiry.

Could you please post a snippet of code region which loads the license and we will take a closer look.

Please note that setting a license everytime you have a request is a bit wasteful, as the license only needs to be set once per application domain. Please see this page When to Apply a License to learn about when a license needs to be set.

Thanks,

Hi Adam,

Thanks for the reply! We have a custom HttpHandler class and we set the license in the ProcessRequest method. Here is a sample code snippet:

public class MyCustomHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        string binPath = Path.Combine(context.Request.PhysicalApplicationPath, "bin");
        string licenseFile = Path.Combine(binPath, "Aspose.Total.lic");
        if (System.IO.File.Exists(licenseFile))
        {
            Aspose.Words.License licenseWord = new Aspose.Words.License();
            licenseWord.SetLicense(licenseFile);
        }
        if (System.IO.File.Exists(licenseFile))
        {
            Aspose.Slides.License licenseSlides = new Aspose.Slides.License();
            licenseSlides.SetLicense(licenseFile);
        }
    }
}

We have a few production servers which are IIS 6 and a few are IIS 7.5. So far this is happening intermittently on the IIS 7.5 server. We haven’t seen this issue on the IIS 6 servers. Since, this is on production, it has become a very critical issue for us. Your prompt help in fixing this issue is greatly appreciated.

Hi Bin,

Thanks for posting your code.

I can see nothing technically wrong with the code you have posted. It should work as expected. It seems strange this issue is occuring in IIS 7.5 but not 6.0. My advise would be to try move this license setting code to the Application_Start method in Global.asax.vb file. This may just solve any issues and also give a bit of a performance boost as well.

Thanks,

Hi Adam,

Ours is a class library, so I guess, I’ll try adding it to a static constructor.
But, it doesn’t give us the comfort that this will indeed resolve the issue as we haven’t been able to really root cause it. Is there anything else that can be done to root cause it?

Thanks for your help!

Hi Bin,

Thanks for this additional information. You are correct, there have a few other customers with this sort of issue but each time we were unable to reproduce the issue, so were unable to investigate and fix what might be causing it. In the past I have tested using a simple project which loads the same license hundreds of times. I was unable to reproduce any problems though.

My guess is it would be something to do with simultaneous requests on the server. As I suggested before, it would be much more efficient just to set the license once, however if you still want to retain the layout of how you are setting the license right now, I would suggest instead loading the license only once through the use of a singleton class. This class would instantiate only a single instance of a stream object containing the license and will pass that object to the SetLicense method with each request. Remember to reset the stream pointer back to 0 each time before use. If you do try this please give us feedback as it may help in future cases.

You may also want to consider logging and catching of these exceptions and see if you can discover some sort of pattern to this issue.

Thanks,