Free Support Forum -

Excel file causing ViewerHtmlHandler.GetPages Method to throw exception

I have the following code:
byte[] attachmentData = new byte[0];
List documentPages = new List();
int? totalPages = (int?)null;

        if (!string.IsNullOrEmpty(adminPortalViewModel.FileName))
            HttpPostedFileBase file = Request.Files[0];
            Stream stream = file.InputStream;
            if (adminPortalViewModel.MaterialType == "Document")
                attachmentData = new byte[file.ContentLength + 1];
                stream.Read(attachmentData, 0, file.ContentLength);

                ViewerConfig config = new ViewerConfig();
                ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler(config);
                HtmlOptions htmlOptions = new HtmlOptions();
                htmlOptions.IsResourcesEmbedded = true;
                htmlOptions.PdfOptions.EnablePreciseRendering = true;

                List<PageHtml> pages = htmlHandler.GetPages(stream, htmlOptions);
                totalPages = pages.Count();
                documentPages = new List<DocumentPageData>();
                foreach (PageHtml pageHtml in pages)
                    documentPages.Add(new DocumentPageData() { PageHtml = pageHtml.HtmlContent });

My exception is being throw on the line: List pages = htmlHandler.GetPages(stream, htmlOptions);

I’ve attached the file that is causing issues: (9.5 KB)
ocsViewerException: ‘Object reference not set to an instance of an object.’


Thanks for using GroupDocs.Viewer for .NET. We have successfully reproduced your reported issue at our end. The issue has been logged in our Issue Tracking System (with ID: VIEWERNET-1425) for further investigation. In case of any updates, we’ll keep you informed.


Your reported issue has been resolved and its fix is planned to be included in the upcoming version (17.11) of GroupDocs.Viewer for .NET. This issue was introduced in version 17.10 however, the document is getting rendered without any issue using version 17.9. Therefore, you can also use version 17.9 until the release of the upcoming version of GroupDocs.Viewer for .NET.


The issue you have found earlier (filed as VIEWERNET-1425) has been fixed in this update.