License not being applied

Hi,

We have a piece of code where we are generating PDF files, and before we do that, we register our license. This works good for us in 2 environments, but not in one of our environments. The license file is found and registered without raising any exception but when the pdf files are prepared, they have the following message: “Evaluation Only. Created with Aspose.PDF. Copyright 2002-2020 Aspose Pty Ltd.”

Our license is valid till 2023, and I am getting this with version 22.4.0 of Aspose.PDF package.

Our application is a .NET 6 Azure Function running on an azure function app.

Can you please help ?

Regards,

@rahulsinha

Can you please share the sample code snippet that you are using to generate the PDF file? Also, please make sure that the correct license file is placed in the directory. You can share your license file with us in a private message as well so that we can test the scenario in our environment and address it accordingly. You can click over username and press the blue message button to send a private message.

This is the snippet we are using for generating the file. The thing is the code works well in our 2 other environments, but not in the main Production environment. The license file is the same as well in all 3 environments. error.png (9.6 KB)
log_message.png (7.4 KB)

[FunctionName("AnnexGeneratorFunction")]
[return: ServiceBus("%AnnexGeneratorFunction.Topic%", Connection = "AnnexGeneratorFunction.Topic.ServiceBusConnection")]
public async Task<ServiceBusMessage> Run([ServiceBusTrigger("%AnnexGeneratorFunction.Queue%", Connection = "AnnexGeneratorFunction.Queue.ServiceBusConnection")] 
	GenerateAnnexRequestMessage message, ExecutionContext context, ILogger logger)
{
	logger.LogInformation("Start generating annex.");
	SetLicense(context.FunctionAppDirectory, logger);
	var result = await Service.GenerateAsync(message);

	logger.LogInformation("Annex generated.");

	return CreateMessage(message, result);
}


private void SetLicense(string directory, ILogger logger)
{
	string licensePath = Path.Combine(directory, "Aspose.Total.lic");
	logger.LogInformation("Searching Aspose license in: {0}", licensePath);

	if (File.Exists(licensePath))
	{
		var licensePdf = new License();
		licensePdf.SetLicense(licensePath);
	}
	else
	{
		logger.LogCritical($"Please put aspose license file Aspose.Total.lic at {licensePath}");
	}
}

// Service method creating pdf file
public async Task<AnnexGeneratedResponseMessage> GenerateAsync(GenerateAnnexRequestMessage input)
{
	try
	{
		Logger.LogInformation("Creating annex generator.");
		var generator = await Factory.CreateAsync(input.BillProposalId);

		if (generator == null)
		{
			var outputMessage = "billProposalId is not set.";
			Logger.LogWarning(outputMessage);
			return CreateFailureMessage(input, outputMessage);
		}

		Logger.LogInformation("Generating document.");
		using var outputStream = new MemoryStream();
		generator.Generate(outputStream, input.InPreview);

		Logger.LogInformation("Uploading document.");
		string output = StorageService.UploadBlob($"{Guid.NewGuid()}.pdf", outputStream, AnnexContainer);

		return CreateSuccessMessage(input, output);
	}
	catch (Exception ex)
	{
		Logger.LogError("--- FAILED ---{0}{1}", Environment.NewLine, ex);
		return CreateFailureMessage(input, $"{ex.GetType()}: {ex.Message}");
	}
}

@rahulsinha

It is quite hard to determine the cause behind this issue with this little information. Can you please try to set license using other methods mentioned in the documentation? Also, please try to set the license in the same method where PDF is being generated and see if issue still persists. It is also possible that license is not being set due to async calls. If issue still persists, please let us know. We will open an investigation ticket and share the ID with you.