Aspose PDF setLicense Exception

getting this error when calling the code below:

        var pdflicense = new Aspose.Pdf.License();
        pdflicense.SetLicense("Aspose.Total.lic");

System.Exception: ‘Exception of type ‘System.Exception’ was thrown.’
System.Exception
HResult=0x80131500
Message=Exception of type ‘System.Exception’ was thrown.
Source=Aspose.PDF
StackTrace:
at #=qWmCOORAyJAipI4RmFtdXSRLO3$5GxY$f6V$nxTxb$Ak=.#=zgamExwLbaD5xiFdTbDpPcDc=(Object #=zYsrXNow=)
at #=qWmCOORAyJAipI4RmFtdXSRLO3$5GxY$f6V$nxTxb$Ak=.#=zgroikeC8OBAcEIkBYcsg$No=(Object #=zYsrXNow=)
at #=qWmCOORAyJAipI4RmFtdXSRLO3$5GxY$f6V$nxTxb$Ak=.#=zqegfFMAXJ$CbMMlFdIKm_mtnpcY3kcY1jQCAgVn9_dzg()
at #=qWmCOORAyJAipI4RmFtdXSRLO3$5GxY$f6V$nxTxb$Ak=.#=zDukrOE47x0IxoE0yx40WdFq$7y87(Object #=zYsrXNow=, UInt32 #=z_iTKe1s=)
at #=qWmCOORAyJAipI4RmFtdXSRLO3$5GxY$f6V$nxTxb$Ak=.#=zD0d998gVenNnaLliemz42Z9ktRYQPfWRFQsdruI=(Boolean #=zYsrXNow=)
at #=qWmCOORAyJAipI4RmFtdXSRLO3$5GxY$f6V$nxTxb$Ak=.#=zHmeKtAZEzKn$AX_R6zMdf6NsbnSS(Object[] #=zYsrXNow=, Type[] #=z_iTKe1s=, Type[] #=zqNI9Xjs=, Object[] #=zD1ztUlc=)
at #=qWmCOORAyJAipI4RmFtdXSRLO3$5GxY$f6V$nxTxb$Ak=.#=z34AUdGAI_$9uzybgysvkZ3ymesRnVgj5jw==(Stream #=zYsrXNow=, String #=z_iTKe1s=, Object[] #=zqNI9Xjs=, Type[] #=zD1ztUlc=, Type[] #=zzmvmM$U=, Object[] #=zGFQlr_o=)
at Aspose.Pdf.License.SetLicense(String licenseName)
at ConsoleApp6.Program.Main(String[] args) in

@eugene.chng

It looks like you’re encountering an exception when trying to set the license for Aspose.PDF. This issue can arise from a few common causes. Here’s a step-by-step approach to diagnose and resolve the problem:

  1. Check License File Path: Ensure that the path to your license file (“Aspose.Total.lic”) is correct. If the file is not found, it will throw an exception. Use an absolute path to avoid any issues with relative paths.

  2. File Permissions: Verify that your application has the necessary permissions to access the license file. If the file is located in a restricted directory, it may not be accessible.

  3. License File Validity: Make sure that the license file is valid and not expired. You can check the license details by opening the file in a text editor.

  4. Correct API Usage: Ensure that you are using the correct method to set the license. The method SetLicense should be called before any other Aspose.PDF operations.

  5. Catch Exceptions: Wrap your license setting code in a try-catch block to capture more specific error messages, which can help in diagnosing the issue further.

Here’s a sample code snippet to illustrate how to set the license properly:

try
{
    var pdfLicense = new Aspose.Pdf.License();
    pdfLicense.SetLicense("Aspose.Total.lic");
}
catch (Exception ex)
{
    Console.WriteLine("Error setting license: " + ex.Message);
}

If you follow these steps and still encounter issues, please provide any additional error messages or context, and I will assist you further. Please implement these solutions, and let me know how it goes!

Hi,
Below is the error message after executing:
Error setting license: Exception of type ‘System.Exception’ was thrown.

@eugene.chng

Can you please make sure that you are using the latest version of the API? Please download the latest version from NuGet Package Manager and try again. In case issue still persists, you can please share sample Console Application with which we can try to replicate the issue in our environment. We will further proceed to assist you accordingly.

My license does not support the latest api, expired on 2020-10. Please advise as the license is the full package and should be able to utilize the aspose.pdf dll.

@eugene.chng

That means the license can be used up to 20.9/20.10 version(s) of the API. Have you tried with these versions? Can you please share your license file with us in a private message so that we can test it in our environment and address the issue accordingly? You can click on the username and press Blue Message Button to send a private message.

Please find the environment below:
.Net 6.0
Aspose.Pdf - error
Aspose.Words - 19.12.0
Aspose.Cells - 19.12.0
Aspose.Zip - 19.12.0

@eugene.chng

The issue appears to stem from using an older version of Aspose.PDF for .NET with .NET 6.0. Support for the SetLicense() method under .NET 6.0 was introduced in version 21.11 of the API. To resolve this problem, we recommend upgrading to the latest version of the API. If you have any additional questions or concerns, don’t hesitate to let us know.