Hi, a recent problem has cropped up and upgrading versions of Aspose.Words does not rectify it.
We are seeing a StackOverflowException from within Aspose.Words when calling our C# .NET Framework v4.7.2 DLL which implements it.
This is the (abbreviated) code from within our DLL which uses Aspose Words to embed a TIFF document into a blank Word document in a TIFF->PDF conversion. I have excluded the part which handles multi-page TIFFs because this fails for a single-page TIFF as well.
public byte[] ConvertImageToPDF(byte[] tiffBytes)
{
Document document;
DocumentBuilder docBuilder;
Image image;
// Create a new document
document = new Document();
docBuilder = new DocumentBuilder(document);
// Create a new image for insertion
using (var ims = new MemoryStream(tiffBytes))
{
image = Image.FromStream(ims);
docBuilder.InsertImage(image);
}
// further save code which is never reached due to StackOverflow exception on InsertImage
// when called via COM from an application coded in Delphi
}
This code is called via COM on Windows from a Delphi application. Without a debugger attached, the Delphi application crashes when the StackOverflowException is thrown from within the wrapper library’s Aspose Words DocumentBuilder.InsertImage call. With a debugger attached, our IDE catches an Invalid Float Operation error.
This issue seems to occur when calling the Aspose.Words library using C# .NET Framework v4.7.2 via COM, but I can’t tell if it’s limited to our specific implementation.
To the best of my knowledge, this has only started occurring recently, and it may be due to a Microsoft update to the .NET Framework via a security patch or other KB.
It seems you are encountering a StackOverflowException when using the DocumentBuilder.InsertImage method in Aspose.Words while working with a TIFF image in a Delphi application via COM. This issue may be related to how the image is being processed or the interaction between the .NET Framework and the COM interface.
Here are a few suggestions to help troubleshoot and potentially resolve the issue:
Image Format: Ensure that the TIFF image you are trying to insert is not corrupted and is in a supported format. You might want to test with a different single-page TIFF image to see if the problem persists.
MemoryStream Usage: When creating the MemoryStream for the image, ensure that the stream is properly disposed of after use. You can also try using a different method to load the image, such as directly from a byte array if you have the image data available.
Insert Image from Byte Array: Instead of using the Image object, you can try inserting the image directly from a byte array. Here’s an example of how to do this:
public byte[] ConvertImageToPDF(byte[] image)
{
Document document = new Document();
DocumentBuilder docBuilder = new DocumentBuilder(document);
// Insert image from byte array
docBuilder.InsertImage(image);
// Save the document (add your save logic here)
// document.Save("output.pdf");
}
COM Interop: Since the issue occurs when called via COM, ensure that your Delphi application is correctly handling the COM objects. You might want to check for any updates or patches for the .NET Framework that could affect COM interop.
Debugging: If possible, try to isolate the issue by creating a simple console application that uses the same code to insert the image. This can help determine if the problem is specific to the Delphi application or the Aspose.Words library itself.
Version Compatibility: Since you mentioned that the issue started occurring recently, verify if there were any updates to the .NET Framework or the Aspose.Words library that might have introduced this behavior. If possible, try reverting to a previous version to see if the issue persists.
If these suggestions do not resolve the issue, consider reaching out to Aspose support with detailed information about the TIFF image and the environment setup for further assistance.
Feel free to ask if you have any more questions or need further clarification!
procedure UseAsposeWords;
var
saved8087CW: Word;
begin
saved8087CW := Default8087CW;
try
// Disable all floating-point exceptions.
Set8087CW($133F);
// Now we are ready to use code from the Aspose.Words assembly.
// ...
finally
Set8087CW(saved8087CW);
end;
end;
Inside the .NET assembly by importing and calling the “_controlfp” function from “msvcrt.dll”. However, the second approach implies dependency on a third-party DLL so it might be not suitable in the case.