I've found a problem where the SfRichTextBoxAdv control will throw an exception in a way that can't be handled when trying to load a corrupted .docx file.
I'm using this code in code-behind to load a document that I know is not formatted correctly.
// data contains random bytes
Stream stream = new MemoryStream(data);
try
{
RichTextViewer.Load(stream, FormatType.Rtf);
}
catch (Exception e)
{
// This code never seems to actually get hit.
// The RichTextBoxAdv control will instead throw an exception later that we have no way of handling.
logger.LogError("The document could not be opened because an exception occurred.", e);
}
As you can tell by the comments, the catch statement is never entered, and the call to Load completes successfully. However, after my code has completed, an unhandled exception occurs. I can catch it in the Application.UnhandledException event; however at this point it is too late and the app shuts down.
This is the exception that occurs:
System.IO.InvalidDataException: End of Central Directory record could not be found.
at System.IO.Compression.ZipArchive.ReadEndOfCentralDirectory()
at System.IO.Compression.ZipArchive.Init(Stream stream, ZipArchiveMode mode, Boolean leaveOpen)
at System.IO.Compression.ZipArchive..ctor(Stream stream, ZipArchiveMode mode, Boolean leaveOpen, Encoding entryNameEncoding)
at System.IO.Compression.ZipArchive..ctor(Stream stream)
at Syncfusion.Compression.Zip.ZipArchive.<Open>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__4(Object state)
at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()
Just to reiterate - I'm expecting an exception because the document is corrupted, but I need it to occur in a way that it can be handled.
Thanks!