License error randomly appearing

I am using Aspose words in an asp.net v2.0 application using C#. A correct license file has been copied into the bin directory of the website where the aspose dll is contained. However we seem to get random messages saying that the license has not been applied. These messages also go away when you refresh the page. The code we are using is as follows.

Document doc = new Document(stream);
License license = new License();
license.SetLicense("Aspose.Words.lic");
doc.SaveOptions.HtmlExportTextInputFormFieldAsText = true;
using (Stream output = new MemoryStream())
{
    doc.Save(output, SaveFormat.Html);
    using (StreamReader sr = new StreamReader(output))
    {
        sr.BaseStream.Position = 0;
        html = sr.ReadToEnd();
        ok = true;
    }
}

Hi
Thanks for your inquiry. This occurs because you are setting license after creating Document. You need to set license before instantiating any other Aspose.Words classes. Please see the following link to learn when to apply license:
https://docs.aspose.com/words/java/licensing/
Best regards.