We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Handling an exception from SfRichTextBoxAdv

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!

1 Reply

GT Gunasekaran T Syncfusion Team January 23, 2014 10:50 AM UTC

Hi Timothy,

Thank you for your interest in Syncfusion products.

We are able to reproduce the mentioned issue with exception not trigger on loading corrupted Word document (.docx) in SfRichTextBoxAdv. We will fix this issue and this fix will be included in our upcoming refresh release or main release 2014 Volume 1. We will let you know once our refresh release or main release 2014 Volume 1 has been released. You may also check our website periodically for latest information related to our release.

Please let us know if you have any other questions.

Regards,
Gunasekaran


Loader.
Live Chat Icon For mobile
Up arrow icon