Aspose PDF for .NET License not working in Azure

Hello,

I have the most current Aspose .NET Total
and using Nuget packages
Word v21.5.0
PDF version: 21.5.0
Barcode v21.4.0

I created a very simple .NET CORE 3.1 API and published to Azure.
When I run the app locally, this API method works fine,
But when I deploy to Azure as an App Service
The PDF license causes error.
see the code below…

[Route(“Test”)]
[HttpGet]
public IActionResult Test()
{
try
{
// these 2 lines work fine.
Aspose.Words.License wordlicense = new Aspose.Words.License();
wordlicense.SetLicense(“Aspose.Total.NET.lic”);

            // The 2 lines below DO NOT work and I get a HTTP 500 Error in Azure
            // also the try catch block does not get triggered.
            Aspose.Pdf.License pdflicense = new Aspose.Pdf.License();
            pdflicense.SetLicense("Aspose.Total.NET.lic");

            // these 2 lines work fine
            Aspose.BarCode.License barCodeLicense = new Aspose.BarCode.License();
            barCodeLicense.SetLicense("Aspose.Total.NET.lic");

            return Ok("All Aspose Lics are initialized");

        }
        catch (Exception ex)
        {
            return Ok($"{ex.Message}<br/><br/>{ex.StackTrace}");
        }
    }

@tony.woods.bell.ca

Can you please share the details of the issue incurring on your end along with stack trace if there is any. It’s likely that API may not be able to access the file or the path where API is expecting license does not have license file.

Hello,

I am not able to catch any runtime error as that code does not get triggered.
I have my lic file as embedded.
I also tried to copy lic file to deployment but still did not work.

@tony.woods.bell.ca

Can you please share your narrowed down sample application for investigating the issue.

hello
attached is a very simple .NET Core 3.1 web api project
with a Pdf Controller method.

Please create an APP SERVICE in Azure
Then deploy to App service
then fire the api.

[Route(“LicTest”)]
public IActionResult LicTest()
{
Aspose.Pdf.License pdflicense = new Aspose.Pdf.License();
pdflicense.SetLicense(“Aspose.Total.NET.lic”);

        return Ok("Pdf License worked!");
    }

Thank you.
PdfTestApi.zip (10.4 KB)

@tony.woods.bell.ca

I have worked with the sample project and the issue is owing to license file path on your end. Please try using following modified class on your end. I have handled exception in following code which shall tell you where it is expecting the license file to be on your machine.

public class PdfController : ControllerBase
{
    private readonly IHostingEnvironment _hostingEnvironment;
    public PdfController(IHostingEnvironment hostingEnvironment)
    {
        _hostingEnvironment = hostingEnvironment;
    }

    [Route("LicTest")]
    public IActionResult LicTest()
    {
        try
        {
            Aspose.Pdf.License pdflicense = new Aspose.Pdf.License();
 
            string webRootPath = _hostingEnvironment.WebRootPath;
 
            //pdflicense.SetLicense(contentRootPath + @"\Conholdate.Total.Product.Family.lic");
                 pdflicense.SetLicense(contentRootPath + @"\Aspose.Total.NET.lic");

            return Ok("Pdf License worked!");
        }
        catch(Exception e)
        {
            return BadRequest(e.Message);
        }
    }
} 

image.png (145.1 KB)