The isLicensed() method in com.aspose.words.License is deprecated

the isLicensed() method in com.aspose.words.License is deprecated can you provide an updated method to check and make sure the license is applied correctly?

@dfplive

You can use License.SetLicense method to achieve your requirement. This method raises an exception if license is invalid.

Whoever did remove the IsLicensed should rethink the decision because of bad performance.
Given is the following code.

           var sw = Stopwatch.StartNew();
            for (int i = 0; i < 100; i++)
            {
                if (!lic.IsLicensed)
                    lic.SetLicense("aspose.lic");
            }

            Console.WriteLine($"time in ms: {sw.ElapsedMilliseconds}");

Time for execution with check for IsLicensed is 100ms
Time for execution without this check is 1400ms

There are some scenarios where we use aspose multiple times and we can’t be sure whether the license is already set(And we don’t want to track this ourself). In this case, the new version is much worse in terms of performance than the old one.

@dfplive, @manuelk,

You guys can declare a global variable to determine whether a valid license has already been applied:

Java code:

boolean isLicensed = false;
try {
    License lic = new License();
    lic.setLicense("E:\\temp\\aspose.total.java.lic");
    isLicensed = true;
} catch (IllegalStateException ex) {
    isLicensed = false;
}

if (isLicensed) {
    Document doc = new Document("E:\\temp\\in.docx");
    doc.save("E:\\Temp\\awjava-19.10.pdf");
} else {
    System.out.println("License not applied");
}

In Java, the License.setLicense() method will throw IllegalStateException for an invalid/wrong/expired license etc. It throws InvalidOperationException in case of .NET.

C# draft code:

var license = new Aspose.Words.License();
var isWrongLicense = false;
try
{
    license.SetLicense("license.lic");
}
catch (InvalidOperationException)
{
    isWrongLicense = true;
}

Hope, this helps in achieving what you are looking for.

Yes, i’m aware about this.
My point is this: The exact same thing already worked by using IsLicensed() out of the box. Now i need to change my code without any obvious reason.

@manuelk,

I am afraid, License.IsLicensed property was marked as obsolete in Aspose.Words 19.6 (see release notes). And later we had removed this property because of security reasons. You now need to write your own code to be able to detect if a valid license is already applied or not. We apologize for any inconvenience.

We do have a windows service which we use to check for incoming emails.
If we set the license once and cache it based on your sample, will it remain valid over time, or might it become invalid after days/weeks?

@manuelk,

The applied license will remain valid over time. Please just follow these simple rules as described here:

The license only needs to be set once per application domain and you need to set the license before using any other Aspose.Words classes.