Getting a crash while converting a doc

Hi,

I am getting the following call stack intermittantly.

Timestamp: 26/07/2022 07:29:02
Message: System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+.
at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
at    . (Stream )
at Aspose.Words.Rendering.ShapeRenderer.Save(Stream stream, ImageSaveOptions saveOptions)
at    . (Boolean ,   )
at    . ()
at    . (ShapeBase , Shape , ShapeRenderer ,    )
at   . (ShapeBase )
at   . (ShapeBase )
at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
at    . (Section , Boolean )
at    . (Section )
at    .  ()
at    . ()
at    . ()
at    .        (     )
at Aspose.Words.Document. (Stream , String , SaveOptions )
at CdcSoftware.Respond.BusinessLayer.DocumentTemplateManager.CreateEmail(Case caseObject, Guid templateId, Guid languageTemplateId, Guid selectedEntityId, DataObjectCollection`1 configurableCustomVariables, Dictionary`2 entityInstanceSelections, Guid attachmentId, Boolean embedImages)

Could you please explain it and help me to resolve it.

Thanks and Regards,
Harshit

@harshit Could you please attach the problematic document along with code that will allow us to reproduce the problem? We will check the issue and provide you more information.

Hi @alexey.noskov,

We can’t share the template as it’s happening at the customer side however, we are using the following code:

FileTransferInfo templateInfo = GetTemplate(languageTemplateId);
SaveFormat saveFormat = saveAsPlainText ? SaveFormat.Text : SaveFormat.Html;

using (MemoryStream memoryStream = new MemoryStream(templateInfo.Bytes, true))
{
	Document wordDocument = new Document(memoryStream);
	RemoveTemplateVariables(wordDocument);
	ReplaceBookmarkTextInTemplate(caseObject, selectedEntityId, emailTemplate, wordDocument, configurableCustomVariables, entityInstanceSelections);

	using (MemoryStream outputStream = new MemoryStream())
	{
		_activityImages = new Dictionary<string, MemoryStream>();

		if (saveAsPlainText)
		{
			TxtSaveOptions saveOptions = SaveOptions.CreateSaveOptions(saveFormat) as TxtSaveOptions;
			saveOptions.Encoding = Encoding.UTF8;

			wordDocument.Save(outputStream, saveOptions);
			emailData = outputStream.GetBuffer();
		}
		else
		{
			HtmlSaveOptions saveOptions = SaveOptions.CreateSaveOptions(saveFormat) as HtmlSaveOptions;
			saveOptions.Encoding = Encoding.UTF8;
			saveOptions.ImageSavingCallback = this;

			wordDocument.Save(outputStream, saveOptions);
			emailData = outputStream.GetBuffer();
		}                    
	}
}

I hope this will help you in identifying the root cause.

Thanks and Regards,
Harshit

@harshit Thank you for additional information. Unfortunately, it is impossible to analyze the issue without the problematic document. According to the provided stack trace the exception occurs upon rendering some shape while converting the document most likely to HTML. But it is impossible to provide more information without the problematic document.
Please note, it is safe to attach the documents in the forum, only you and Aspose staff can download the files.

HI @alexey.noskov,

Please find the problematic document here.

Refer to Supplier for Resolution Emailen-ZA.zip (41.2 KB)

Hope this will help you in understanding the root cause. Please let us know what is causing the issue and how to fix it.

Thanks and Regards,
Harshit Agrawal

@harshit Thank you for additional information. Unfortunately, I was unable to reproduce the problem on my side using the latest 22.11 version of Aspose.Words. The document is properly converted to HTML without any exceptions on my side. Could you please create a simple console application that will allow us to reproduce the problem? We will check the issue and provide you more information.

Hi @alexey.noskov,

Here is the sample code and template.
Refer to Supplier for Resolution Emailen-ZA.zip (4.2 MB)

We are also not able to replicate it but our customers are facing this issue very frequently.
We have used Aspose Word v13.10.0.0 in our application.

Hope this will help you in understanding the root cause. Please let us know what is causing the issue and how to fix it.

Thanks and Regards,
Harshit Agrawal

@harshit Unfortunately, I cannot reproduce the problem on my side using your test application. Also, 13.10 version is quite old, it was released about 9 years ago. So I would suggest you to update to the latest version of Aspose.Words.

Hi @alexey.noskov,

We are not able to replicate it however following things can help us

  • Can you check the template and let us know what item might cause this issue so that we can work on that?
  • What shapes are there which might result in this?
  • Can you run this template through performance testing in your R&D?
  • Any previous similar issues you got around this area? If yes, how you have resolved those?

Upgrading it to the latest version is a long process of approval and it will increase the testing scope. As of now, we are trying to understand the root cause so that we can create a workaround and keep our customers up and running.

Thanks and Regards,
Harshit Agrawal

@harshit I have checked your document. There are 3 shapes in it. Two of them are regular images and one shape is line shape with zero height. Probably this shape causes the problem on your customers side:

Document doc = new Document(@"C:\Temp\in.doc");
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
foreach (Shape s in shapes)
{
    Console.WriteLine(s.ShapeType);
    Console.WriteLine(s.SizeInPoints);
}

Here is output of this code:

Image
{Width=468.05, Height=65.75}
Line
{Width=108, Height=0}
Image
{Width=206.2, Height=62.25}

But, unfortunately, it is hard to say for sure without ability to reproduce the problem.