SAP Knowledge Base Article - Public

1728783 - Error: A generic error occurred in GDI+ while viewing report in a WPF application

Symptom

  •  Using Crystal reports SDK for VS .NET - Crystal Reports WPF viewer
  • Reports in the application work with MS SQL 2005
  • Reports frequently, but randomly fail with the error: System.Runtime.InteropServices.ExternalException was unhandled
  • Message=A generic error occurred in GDI+.
  • Source=System.Drawing
  • ErrorCode=-2147467259 

      StackTrace:

      at System.Drawing.Image.Save(Stream stream, ImageCodecInfoencoder, EncoderParameters encoderParams)

      at System.Drawing.Image.Save(Stream stream, ImageFormat format)

      at SAPBusinessObjects.WPF.ViewerShared.PageRender.drawImageInstance(ImageObjectInstance imageObjectInstance, VisualCollection visuals)

Environment

  • Crystal Reports for Visual Studio 2010
  • Visual Studio 2010
  • WPF Application

Cause

GDI error mainly occurs due following reasons:

  • Memory management issue.(e. g. not closing and disposing dataset)
  • Permissions issue (e. g. not enough permissions on a particular directory or folder)

Resolution

Workaround available is:

  • Ensure that the dataset is reused.
  • In case using a new dataset ensure that the old dataset is handled(use .Close and .Dispose).
  • Ensure that necessary permissions are set to access a particular folder or directory used by application.

Keywords

GDI error .net, CRVS2010, CR4VS2010 SDK , KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , Problem

Product

SAP Crystal Reports, developer version for Microsoft Visual Studio