Memory Steam is not expandable error after applying lic file

If I create a license ( Aspose.Pdf.Kit.License lic = new Aspose.Pdf.Kit.License();
FileStream myStream = new FileStream("Aspose.Pdf.Kit.lic", FileMode.Open);
lic.SetLicense(myStream);
myStream.Close();)

before or in the following method I receive an error. System.NotSupportedException (Memory Stream is not expandable)

If I don't create a license it works as it should (all be it with the demo text)

private static byte[] RenderReadOnly(byte[] incoming)
{

MemoryStream inStream = new MemoryStream(new byte[incoming.Length]);
inStream.Write(incoming, 0, incoming.Length);

MemoryStream outStream = new MemoryStream(new byte[incoming.Length]);

PdfFileSecurity pdfs = new PdfFileSecurity(inStream, outStream);
try
{

pdfs.SetPrivilege(DocumentPrivilege.Print); // error occures here.
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
inStream.Close();
outStream.Close();

byte[] result = outStream.ToArray();
pdfs = null;
return result;


}

Hello,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for considering Aspose.

I have tested the code at my end and was able to re produce the error. But as you mentioned in your comments, if we don’t create license it works fine. I am receiving the same error in either case. If it does not violate your policy, can you please share the project with us in order for us to have more understanding.

Hi,

You should modify your code like the following:

MemoryStream outStream = new MemoryStream();

Removing size from the MemoryStream constructor, does indeed resolve the issue. Thank you for the quick and accurate reply!