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

Free Support Forum - aspose.com

WarningCallback not called when loading from MemoryStream

[Aspose.Words .NET v23.3.0] I am trying to detect if the docx file that I am loading is corrupted. When I try to load the corrupted document from a file path, the LoadOptions { WarningCallback } is triggered. If however I try to load that same document from a stream, the WarningCallback is not triggered.
(I have the document as a byte[] that I loaded into a MemoryStream)

@kuenne sorry, I can’t reproduce your issue, can you please attach your source file?

Here is a zip file with the corrupted docx file I’m using and some NUnit tests using it.

Aspose.Words.LoadTest.zip (36.7 KB)

1 Like

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-25154

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@kuenne looks like the corrupted part of the file in the header of the file, when you load the file in the memory stream the stream loose this part and Aspose.Words API force it interpretation, even if the result is not the expected.
Regarding the WarningCallback calls, when I load the file from the stream I didn’t get any Warning method call (I just receive an Exception), same happened when I load from the stream (except for the Exception part), so the WarningCallback behavior is consistent for both cases.

@kuenne The attached document is actually not a DOCX document, but a simple JPEG image with .docx extension. You can use FileFormatUtil to detect document format before loading the document. This can help to filter out such documents.

FYI @eduardo.canal

The docx file I provided was created for testing purposes – i.e. we hacked a file so that MS Word displays a prompt that the file is corrupted. This same file does NOT indicate it is an invalid docx file when loading through Aspose.Words. It shouldn’t matter if it is a valid file with another extension.

@kuenne Yes, I agree that Aspose.Words should throw an exception upon loading this file. I wanted to highlight that you can filter out such invalid files without attempting to load them into the Document.
We will keep you updated and let you know once the issue is resolved or we have more information of you.