GDI+ Error Using Words- PDF and Barcode

We have a service (IIS Hosted) that takes word templates, merges bookmarks in (including a barcode bookmark in most cases) and then converts to pdf which is returned to the calling application as a memory stream

Often this will be a pack of 10+ docs

All of this works fine except we get intermittent GDI+ errors and have to restart the app pool or do an IIS reset to resolve

For reference the error we see is:

2014-06-25 14:07:01,388 [13] ERROR Company.Application.Service.Interceptors.LoggingInterceptionBehavior - Invoke -

Method System.IO.MemoryStream GenerateDay1Documentation(Int32, Boolean, Boolean) threw

EXCEPTION:
System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+.
at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
at System.Drawing.Image.Save(Stream stream, ImageFormat format)
at Company.DocumentGeneration.Merging.MergingHelper.GetBarCodeImageAsByteArray(Int32 departmentId, Int32 caseId, Int32 needsDefinitionId)
at Company.DocumentGeneration.Merging.MergingHelper.UpdateImageBookmark(List`1 bookmarks, Int32 departmentId, Int32 caseId, Int32 needsDefintionId)
at Company.Application.Service.ServiceHelperDocumentation.GenerateDay1Documentation(Int32 caseId, Boolean startConsideration, Boolean fullDuplex)
at Company.Application.Service.ApplicationService.GenerateDay1Documentation(Int32 caseId, Boolean startConsideration, Boolean fullDuplex)
at DynamicModule.ns.Wrapped_IApplicationService_837e2fede52b43f1aee3c729c28f7ead.__61(IMethodInvocation inputs, GetNextInterceptionBehaviorDelegate getNext)

INNER EXCEPTION:


MESSAGE:
A generic error occurred in GDI+.

STACK TRACE:
at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
at System.Drawing.Image.Save(Stream stream, ImageFormat format)
at Company.DocumentGeneration.Merging.MergingHelper.GetBarCodeImageAsByteArray(Int32 departmentId, Int32 caseId, Int32 needsDefinitionId)
at Company.DocumentGeneration.Merging.MergingHelper.UpdateImageBookmark(List`1 bookmarks, Int32 departmentId, Int32 caseId, Int32 needsDefintionId)
at Company.Application.Service.ServiceHelperDocumentation.GenerateDay1Documentation(Int32 caseId, Boolean startConsideration, Boolean fullDuplex)
at Company.Application.Service.ApplicationService.GenerateDay1Documentation(Int32 caseId, Boolean startConsideration, Boolean fullDuplex)
at DynamicModule.ns.Wrapped_IApplicationService_837e2fede52b43f1aee3c729c28f7ead.__61(IMethodInvocation inputs, GetNextInterceptionBehaviorDelegate getNext)

AT:
14:07:01

2014-06-25 14:07:01,388 [13] ERROR Company.Application.Service.Interceptors.LoggingInterceptionBehavior - Invoke -
System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+.
at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
at System.Drawing.Image.Save(Stream stream, ImageFormat format)
at Company.DocumentGeneration.Merging.MergingHelper.GetBarCodeImageAsByteArray(Int32 departmentId, Int32 caseId, Int32 needsDefinitionId)
at Company.DocumentGeneration.Merging.MergingHelper.UpdateImageBookmark(List`1 bookmarks, Int32 departmentId, Int32 caseId, Int32 needsDefintionId)
at Company.Application.Service.ServiceHelperDocumentation.GenerateDay1Documentation(Int32 caseId, Boolean startConsideration, Boolean fullDuplex)
at Company.Application.Service.ApplicationService.GenerateDay1Documentation(Int32 caseId, Boolean startConsideration, Boolean fullDuplex)
at DynamicModule.ns.Wrapped_IApplicationService_837e2fede52b43f1aee3c729c28f7ead.__61(IMethodInvocation inputs, GetNextInterceptionBehaviorDelegate getNext)

Hi Jason,

Thanks for your inquiry. It would be great if you please share following detail for investigation purposes.


  • Please attach your input Word documents.
  • Please

    create a simple web application that demonstrates the code (Aspose.Words code) you used to reproduce this issue.


As soon as you get these pieces of information to
us we’ll start our investigation into your issue.