What happens if the license is invalid?

Hi,

I have a question regarding the Aspose licenses. At runtime, how will I know if the Aspose License is valid or not? I would like to programatically determine if I have an appropriate license for the Aspose Libraries that I use.

I’m expecting some sort of feedback from the SetLicense method, but the API documentation does not detail this.

The reason I’m asking this question is that I’d like to write some unit tests that check that the license we use in development is covered by the licesne that we hold. I want to prevent other developers from upgrading Aspose.Words to a version that we do not have a license for.

Rik

This message was posted using Page2Forum from SetLicense Method - Aspose.Words for .NET

Ah! I’ve discovered that it throws an InvalidOperationException with a message along the lines of:

“The subscription included in this license allows free upgrades until 01 Dec 2010, but this version of the product was released on 16 Apr 2011. Please renew the subscription or use a previous version of the product.”

Note: I’m using .Net

Hi
Thanks for your inquiry. Yes, you are right, Aspose.Words throws an exception when you attempt to set an invalid license.
Also, for testing purposes, you might find the following method useful:

///
/// Returns true if the Aspose.Words license is set.
///
private static bool IsLicenseSet()
{
    // We will insert this text at the beggining of the document.
    // If the license set this text will be in the first paragraph,
    // if not an evaluation watermark will be in the first paragraph.
    const string text = "This is text used to check if the license is set";
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    builder.Write(text);
    // Save and optn the document. If Aspose.Words works in evaluation mote it will add a watermark.
    using(MemoryStream docStream = new MemoryStream())
    {
        doc.Save(docStream, SaveFormat.Doc);
        docStream.Position = 0;
        doc = new Document(docStream);
    }
    // Check text of the first paragraph.
    return (doc.FirstSection.Body.FirstParagraph.ToTxt().Trim() == text);
}

Best regards,