Here’s the stack trace:
Unhandled exception: System.InvalidOperationException:
There was an error setting the license: Authentication failed.
at DocumentServiceLibrary.AsposeTotal.AsposeLicenseManager.SetAsposeMeteredLicense() in /application/app/<>/AsposeTotal/AsposeLicenseManager.cs:line
Here’s the sample code:
using Aspose.Words;
namespace <>.AsposeTotal;
public class AsposeLicenseManager
{
static AsposeLicenseManager()
{
EnvironmentLoader.LoadEnvironmentVariables();
}
public static void SetAsposeMeteredLicense()
{
try
{
if (Metered.IsMeteredLicensed())
{
return;
}
// public and private keys set here
if (string.IsNullOrEmpty(publicKey) || string.IsNullOrEmpty(privateKey))
{
throw new InvalidOperationException("Aspose metered keys are not set in the environment variables.");
}
Metered metered = new Metered();
metered.SetMeteredKey(publicKey, privateKey);
// Retry mechanism to check if the license is applied
int retryCount = 5;
int delay = 1000; // 1 second delay
for (int i = 0; i < retryCount; i++)
{
if (Metered.IsMeteredLicensed())
{
return;
}
System.Threading.Thread.Sleep(delay);
}
throw new InvalidOperationException("Aspose metered license is not applied.");
}
catch (Exception e)
{
throw new InvalidOperationException("\nThere was an error setting the license: " + e.Message);
}
}
}