We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Using Aspose.Words in Azure Function

Hi,

We are using evaluation version of Aspose.Words in a very basic Azure Function and getting an error as soon as the first Aspose document is initialized: ‘The document appears to be corrupted and cannot be loaded’.
Seems like the problem is isolated to Azure Function only, another web project which is using the same code runs fine on the same machine.

Thanks in advance.

@atchouma

We suggest you please use the latest version of Aspose.Words for .NET 20.9 and read the following articles about document conversion at Windows Azure. Hope this help you.
Windows Azure Platform
Converting Documents in Windows Azure

If you still face problem, please ZIP and attach your input Word document here for testing. We will investigate the issue and provide you more information on it.

Thanks for you reply. I downloaded the latest version, but unfortunately it did not fix the issue. I am using the ‘plain vanilla’ example from the article you referenced and code looks like follows:

		log.LogInformation("C# HTTP trigger function processed a request.");

		// Create a simple document using DocumentBuilder.
		Document doc = new Document();
		DocumentBuilder builder = new DocumentBuilder(doc);

		// Write some text in the document.
		builder.Writeln("Hello Aspose.Words!");

		// Write OS we are running on.
		builder.Writeln("You are running on " + System.Environment.OSVersion.VersionString);
		
		// Now save the created document to PDF and return as a FileContentResult.
		using (MemoryStream ms = new MemoryStream())
		{
			doc.Save(ms, SaveFormat.Pdf);
			return new FileContentResult(ms.ToArray(), "application/pdf")
			{
				FileDownloadName = "out.pdf"
			};
		}

The following line results in the error, very first line:
Document doc = new Document();

Error:
(Failed, Id=c36e793a-a0cb-4ee2-81c3-f0cbc78b0a78, Duration=25711ms)
System.Private.CoreLib: Exception while executing function: pdf_convert. Aspose.Words: The document appears to be corrupted and cannot be loaded. Aspose.Words: Object reference not set to an instance of an object.

Error suggests that there is a some kind of reference issue. The same code works fine in non-azure function project on the same machine.

Build target x64

Thanks in advance,
Alex

@atchouma

We are working over your query and will get back to you soon.

@atchouma Could you please zip and attach your project here for testing? I checked the issue using the instructions and code from this article and everything works fine on my side. I will check your project and provide you more information.