Friday, July 20, 2012

SSRS Error Rending Report to MS Word

Ran into a strange issue generating a custom report out of CRM to Microsoft Word today. The report is a customized quote detail which had been working fine to this point. Today when the users tried to generate the report for a quote they had created it would generate fine in the report viewer, fine in PDF but failed with this error when attempting MS Word:

An error has occurred.
Try this action again. If the problem continues, check the Microsoft Dynamics Community for solutions or contact your organization's Microsoft Dynamics CRM Administrator. Finally, you can contact Microsoft Support.

Not much help, so I dug into the SSRS logs and came across these errors:

webserver!ReportServer_0-13!b4c!07/20/2012-13:04:19:: e ERROR: Reporting Services error Microsoft.ReportingServices.Diagnostics.Utilities.RSException: An error occurred during rendering of the report. ---> Microsoft.ReportingServices.ReportProcessing.HandledReportRenderingException: An error occurred during rendering of the report. ---> Microsoft.ReportingServices.OnDemandReportRendering.ReportRenderingException: An error occurred during rendering of the report. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
library!ReportServer_0-13!1e64!07/20/2012-13:04:30:: i INFO: RenderFromSession('/MyORg_MSCRM/CustomReports/{80bc9baf-e166-e111-9983-0800278f3112}')
reportrendering!ReportServer_0-13!1e64!07/20/2012-13:04:31:: e ERROR: Throwing Microsoft.ReportingServices.ReportProcessing.HandledReportRenderingException: An error occurred during rendering of the report., ;
Info: Microsoft.ReportingServices.ReportProcessing.HandledReportRenderingException: An error occurred during rendering of the report. ---> Microsoft.ReportingServices.OnDemandReportRendering.ReportRenderingException: An error occurred during rendering of the report. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Microsoft.ReportingServices.Rendering.WordRenderer.PictureDescriptor.InitImage(Byte[] aImgData, Byte[] aHash, Int32 imgIndex)
   at Microsoft.ReportingServices.Rendering.WordRenderer.PictureDescriptor.CreateDefaultEscherRecords(Byte[] imgData, Byte[] hash, Int32 imgIndex)
   --- End of inner exception stack trace ---
   at Microsoft.ReportingServices.Rendering.WordRenderer.PictureDescriptor.CreateDefaultEscherRecords(Byte[] imgData, Byte[] hash, Int32 imgIndex)
   at Microsoft.ReportingServices.Rendering.WordRenderer.PictureDescriptor..ctor(Byte[] imgData, Byte[] hash, Int32 aWidth, Int32 aHeight, Sizings sizing, Int32 imgIndex)
   at Microsoft.ReportingServices.Rendering.WordRenderer.Word97Writer.AddImage(Byte[] imgBuf, Single height, Single width, Sizings sizing)
   at Microsoft.ReportingServices.Rendering.WordRenderer.WordRenderer.RenderReportItem(RPLElement element, RPLMeasurement measurement, Int32 cellIndex, Single left, BorderContext borderContext, Boolean inTablix)
   at Microsoft.ReportingServices.Rendering.WordRenderer.WordRenderer.RenderRectangle(RPLContainer rectangle, Single left, Boolean canGrow, RPLMeasurement rectangleMeasurement, BorderContext parentBorderContext, Boolean inTablix, Boolean ignoreStyles)
   at Microsoft.ReportingServices.Rendering.WordRenderer.WordRenderer.RenderRectangle(RPLContainer rectangle, Single left, RPLMeasurement rectangleMeasurement, BorderContext parentBorderContext, Boolean inTablix)
   at Microsoft.ReportingServices.Rendering.WordRenderer.WordRenderer.RenderReportItem(RPLElement element, RPLMeasurement measurement, Int32 cellIndex, Single left, BorderContext borderContext, Boolean inTablix)
   at Microsoft.ReportingServices.Rendering.WordRenderer.WordRenderer.RenderRectangle(RPLContainer rectangle, Single left, Boolean canGrow, RPLMeasurement rectangleMeasurement, BorderContext parentBorderContext, Boolean inTablix, Boolean ignoreStyles)
   at Microsoft.ReportingServices.Rendering.WordRenderer.WordRenderer.RenderRectangle(RPLContainer rectangle, Single left, RPLMeasurement rectangleMeasurement, BorderContext parentBorderContext, Boolean inTablix)
   at Microsoft.ReportingServices.Rendering.WordRenderer.WordRenderer.RenderReportItem(RPLElement element, RPLMeasurement measurement, Int32 cellIndex, Single left, BorderContext borderContext, Boolean inTablix)
   at Microsoft.ReportingServices.Rendering.WordRenderer.WordRenderer.RenderRectangle(RPLContainer rectangle, Single left, Boolean canGrow, RPLMeasurement rectangleMeasurement, BorderContext parentBorderContext, Boolean inTablix, Boolean ignoreStyles)
   at Microsoft.ReportingServices.Rendering.WordRenderer.WordRenderer.RenderRectangle(RPLContainer rectangle, Single left, RPLMeasurement rectangleMeasurement, BorderContext parentBorderContext, Boolean inTablix)
   at Microsoft.ReportingServices.Rendering.WordRenderer.WordRenderer.RenderReportItem(RPLElement element, RPLMeasurement measurement, Int32 cellIndex, Single left, BorderContext borderContext, Boolean inTablix)
   at Microsoft.ReportingServices.Rendering.WordRenderer.WordRenderer.RenderTablixCell(RPLTablix tablix, Single left, Single[] widths, TablixGhostCell[] ghostCells, BorderContext borderContext, Int32 nextCell, RPLTablixCell cell, Enumerator omittedCells, Boolean lastCell)
   at Microsoft.ReportingServices.Rendering.WordRenderer.WordRenderer.RenderTablix(RPLTablix element, Single left, BorderContext parentBorderContext, Boolean inTablix)
   at Microsoft.ReportingServices.Rendering.WordRenderer.WordRenderer.RenderRectangle(RPLContainer rectangle, Single left, Boolean canGrow, RPLMeasurement rectangleMeasurement, BorderContext parentBorderContext, Boolean inTablix, Boolean ignoreStyles)
   at Microsoft.ReportingServices.Rendering.WordRenderer.WordRenderer.Render()
   at Microsoft.ReportingServices.Rendering.WordRenderer.WordDocumentRenderer.Render(Report report, NameValueCollection reportServerParameters, NameValueCollection deviceInfo, NameValueCollection clientCapabilities, Hashtable& someProps, CreateAndRegisterStream createAndRegisterStream)
   at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.RenderFromOdpSnapshot(IRenderingExtension newRenderer, String streamName, ProcessingContext pc, RenderingContext rc, GetResource getResourceCallback)
   --- End of inner exception stack trace ---

Again, not much to go on there. A little more testing revealed that there was only an issue with 2 quotes. The reports happen to pull in an image from a URL and display it on the report. The 2 that didn’t work shared one of the same products and in the error detail it mentions an image (picture).  A bit more testing concluded the image was in fact the problem. In the end I simply re-saved the image in Paint.NET and made it available for the reports to grab and the problem was solved.