SetLicense in WCF service

Hi,


We are using Aspose.PDF.Dll (version 10.2.0.0) in a WCF service. Once in a while, we get “Object reference not set to an instance of an object.” at line Aspose.Pdf.License.SetLicense(String licenseName) and the WCF service stops working. We have to reset App pool for the WCF service to make it working again.

The WCF service is configured as
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall)] , It has a class that calls the SetLicense, the license file is included in the project as embedded resource.
license.SetLicense(licenseFileName);
license.Embedded = true;

What’s the best way to avoid this error? It only happens 1% of the time.

Thank you and waiting for your response.




Hi Mary,

Thanks for your inquiry. I am afraid we can not suggest you exact reason of the issue without replicating the issue at our end. Please check following suggestions and if these do no help then please share some sample code to replicate the issue for further investigation.

However, please note, when you you are developing a class library, it is recommended to call License.SetLicense from a static constructor of your class that uses Aspose API. The static constructor will execute before an instance of your class is created making sure Aspose license is properly set.

Moreover, please note we have observed the same exception in multi-threaded environment. The issue arises when we try to use a document in more than one threads. Aspose APIs are multithread safe as long as only one thread works on a document at a time. Different threads can safely work on different documents at the same time.

We are sorry for the inconvenience caused.

Best Regards,

Using static constructor in per call instance mode for WCF service will still create a new instance with each call, will not make any difference.

Regarding the same document being used by more than one thread, can your application handle this exception in a better way so that we don't have to reset app pool to resolve this issue?

Hi Mary,

kemptitle:

Using static constructor in per call instance mode for WCF service will still create a new instance with each call, will not make any difference.

In reference to license implementation, you may try to implement as following depending upon where you have hosted the WCF service. Hopefully it will help you to resolve the issue.

if it is custom ServiceHost - then you can set license in service host start event

if it is IIS - then set license can be called in Global.asax

kemptitle:

Regarding the same document being used by more than one thread, can your application handle this exception in a better way so that we don't have to reset app pool to resolve this issue?

Regrading multi-thread scenario, we have logged an investigation ticket PDFNEWNET-39157 for further investigation. We will let you know our findings asap.

Best Regards,

with WCF percall, it doesn’t see the license object from Global.asax From IIS. It works in Visual Studio. Is there a way to pass the license object in Aspose?



Please provide sample code if there is way.

Hi,


Thanks for using our API’s. We are working on testing the scenario while accessing license in WCF application and will get back to you soon.

Hi Mary,


Thanks for your patience. Our product team has started the investigation of your above reported issue (PDFNETNET-39157). We need your code for analysis, so please share a sample project to replicate the issue at our end to address your issue exactly.

We are sorry for the inconvenience caused.

Best Regards,