Error Converting Docx. A generic error occurred in GDI+


We are getting the following error when converting some of our documents to images. The error doesn’t always happen, and when it happens it happens on different pages.

[ExternalException (0x80004005): A generic error occurred in GDI+.]
   System.Drawing.Graphics.CheckErrorStatus(Int32 status) +94
   System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format) +306
   System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, PointF point, StringFormat format) +79
      .(   , PointF , Font , Brush ) +300
      .(   , PointF , Font ) +183
      .     (   ) +560
     .     (   ) +108
     .     (   ) +39
     .     (   ) +108
     .     (   ) +43
     .     (   ) +108
     .     (   ) +39
     .     (   ) +108
     .     (   ) +39
     .     (   ) +108
     .     (   ) +39
      .(   , Graphics ) +267

I have a document that reproduces the issue. (10.0 MB)

Here is a .NET Framework project that reproduces it. You might need to run it a few times.

@ITS_Systems Thank you for reporting the problem to us. I have managed to reproduce it and logged it as WORDSNET-24590. We will investigate the issue and let you know once it is resolved or we have more information for you.

As a workaround, you can migrate to .NET Standard or .NET6 version of Aspose.Words, these versions use SkiaSharp to deal with graphics and I was unable to reproduce the mentioned problem with these versions.

Thanks for that, migrating to .NET 6 or Standard isn’t really an option for us right now, so hopefully it’s fixable in framework.

@ITS_Systems The issue is currently in the queue for analysis. We will deeply investigate the issue and provide you more information. But I am doubt that the problem is actually in Aspose.Words, I suspect the problem is in System.Drawing itself. If so it might be out of our control.

Thanks, any update on the issue?

@ITS_Systems Unfortunately, there are not news regarding the issue yet.

@ITS_Systems We have completed the analysis of the issue and concluded to close it as not a bug. The exception is thrown from System.Graphics.DrawString(). We have tested this case with several parameters and now we are sure it’s some kind of bug in GDI+ itself. An exception can be thrown from different places in the code. So unfortunately, it is impossible to fix this bug on our side, it should be fixed in GDI+ that is out of our control.

Thanks for the update. I understand thats an issue with System.Graphics.DrawString(), is there any alternative solution, we use this heavily and it has suddenly started to fail. What do you normally do in such situation? report to Microsoft?

We can’t really leave it like this

@ITS_Systems Unfortunately we do not see any other workaround at the moment. As a possible workaround we could provide a .NET Framework 4.6.2 Aspose.Words assembly with Skia graphics rendering instead of GDI+. Please let us know if you are interested in this. I will link your thread to the related request in our defect tracking system.