A Generic error occured in GDI+

I’m experiencing a random error with aspose.words. It’s random in the sense that it comes and goes, And I don’t know why it suddenly stops or why it suddenly begins.

I’ve tried updating aspose.words to the newest version (16.7), but that didn’t do much. It still throws the error once in a while. Also searched google for answers without any luck, as the stacktrace is not very helping.

System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+.
at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
at ?.()
at .(RectangleF , ?? , Int32 , DocumentBase )
at .(?? , Int32 , Single , DocumentBase )
at .( , ArrayList )
at . ? (?? )
at .( , ?? , Boolean )
at .(?? , ?? , Boolean )
at .( , ? , ? , ? , ? , Boolean )
at ? .? ? (? )
at ? .(ShapeBase )
at ? .(ShapeBase , ? )
at ? .( ? , Boolean )
at ? .( ? )
at ? .( )
at . ? ()
at .()
at .(? , ArrayList , ArrayList )
at .(? , ArrayList , ArrayList )
at .()
at ? . ? ? ( )
at ? .( ? )
at ? .( ? , ? )
at .( ? , ? )
at .?? ? ( ? )
at Aspose.Words.Document.(Stream , String , SaveOptions )

Hope anyone in here can tell me what this means. If i’m using aspose.words wrong or not. It’s hard to tell from that stacktrace.

Hi Simon,

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document (and image files if any)
  • Please create a standalone console application (source code without compilation errors) that helps us reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click ‘Reply’ button that will bring you to the ‘reply page’ and there at the bottom you can include any attachments with that post by clicking the ‘Add/Update’ button.

Best regards,

The upload function does not work. I get a 404 when I try to upload the file.

I zipped it and everything.

Hi Simon,

Thanks for your inquiry. I am afraid, there are no attachments found in your email as well.

Please upload it to some file hosting service e.g. Dropbox and share the download link with us for testing.

Best regards,

Hey Awais

I send you an email with the link

Hi Simon,

Thanks for your inquiry. We are working over your query and will get back to you soon.

Best regards,

Hi Simon,
Thanks for your inquiry. After an initial test with Aspose.Words 16.10.0, we were unable to reproduce this issue on our end (see attached Pdf). We would suggest you please upgrade to the latest version of Aspose.Words. You can download it from the following link. Hope, this helps.
https://releases.aspose.com/words/net/
Best regards,

Hey Awais

We updated our aspose version to the newest as you suggested and we still experience the error.

Hi Simon,

Please also tell us the details of the machine environment you’re getting this problem on e.g. the operating system version, its Architecture (32 / 64 bit), .NET Framework version and What DLL of Aspose.Words are you using? (the one that resides in net2.0 or in net3.5_ClientProfile or in net4.0 folder).

We’ll then start further investigation into your issue and provide you more information. Thanks for your cooperation.

Best regards,

Hey Awais

Our application is hosted on:

Windows Server 2008 R2 SP1 Standard
Processor Intel Xeon CPU CPU E7-8891 V2 @ 3.20 GHz (2 processors) | 16,0 GB ram installed
64-bit operating System
IIS Version 7.5
.Net 4.5.2

I’ve had no luck reproducing the error locally

Hi Simon,

I could reproduce System.ArgumentException upon running the following code on my side:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertImage(MyDir + "Ref_1_Graph.MEDCS.eps");

We have logged this issue in our bug tracking system. The ID of this issue is WORDSNET-14406. Your request has also been linked to the appropriate issue and you will be notified as soon as it is resolved. Sorry for the inconvenience.

Best regards,

Any news on a release? Will you make a release here in December?

And can I expect WORDSNET-14406 to be resolved in the next release?

Hi Simon,

Our product team has completed the analysis and the root cause of this issue has been identified. However, because of complexity, the implementation of the fix of this issue has been postponed for now (no ETA is available). We will inform you as soon as this issue is resolved. We apologize for your inconvenience.

Inserting an ‘EPS’ image is not supported by Aspose.Words.

The ‘EPS’ is ‘Encapsulated PostScript’ file format. This format is not natively supported by MS Word. When inserting EPS picture in GUI, MS Word converts it to WMF format. Aspose.Words checks such case and tries to convert it to PNG using system GDI+.

Unfortunately, GDI+ does not support EPS format too: https://msdn.microsoft.com/en-us/library/at62haz6.aspx and also see remarks at https>://msdn.microsoft.com/en-us/library/0cbhe98f.aspx and https://learn.microsoft.com/en-us/dotnet/api/system.drawing.image.fromfile?redirectedfrom=MSDN&view=dotnet-plat-ext-7.0#System_Drawing_Image_FromFile_System_String_

That is why Aspose.Words throws an exception when we create a new Bitmap. So, it seems we need to implement a converter or rasterizer from ‘EPS’ to one of the supported by MS Word image formats to solve the problem.

‘EPS’ is a DSC-conforming PostScript document with additional restrictions.
Note that EPS can have a preview picture of the content, for on-screen display (TIFF or WMF). But, unfortunately, your EPS file does not contain it.

The specification for ‘EPS’ can be found at http://partners.adobe.com/public/developer/en/ps/5002.epsf_spec.pdf

The specification for PostScript language can be found at https://www.adobe.com/products/postscript.html

All Adobe PostScript documentation can be found also at a single place: http://partners.adobe.com/public/developer/ps/index_specs.html (it seems it can be unavailable sometimes)

The additional PostScript Tutorial that can be useful: http://paulbourke.net/dataformats/postscript/

Also, we maybe need to look for a third-party API for converting images.
In addition, we probably should throw an exception with more appropriate description.

Best regards,

Hi Awais

We are still experiencing the error. It is critical for us, that it is solved as fast as possible. Can you give us an update and new eta on the solution?

Hi Simon,

Thanks for your inquiry.

We regret to share with you that there is no further news about this issue and the implementation of this issue has been postponed for now. However, the fix of this problem may definitely come onto the product roadmap in the future.

We have also asked the ETA of this issue from our product team and will update you as soon as any estimates are available.

We apologize for your inconvenience.

Best regards,

Hi Awais

Okay, can you maybe put us in the right direction of a workaround? Other than what you already explained.

Or do you know the specific element in the document and application I send you where it goes wrong?

And could we maybe get in direct contact with the developer who found the bug?

Hi,

Thanks for your inquiry.

The System.ArgumentException occurs when you try to insert EPS image by using the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertImage(MyDir + "Ref_1_Graph.MEDCS.eps");

We have passed your concern to our product team and will inform you as soon as there are any further updates on this topic. We apologize for your inconvenience.

Best regards,

Hi Awais

But the test application I forwarded to you did nothing like the code you just posted

This is what the test application did:

byte[] fileBytes = File.ReadAllBytes("…/…/doc/Brugervejledning.docx");

var document = new Document(new MemoryStream(fileBytes));
var stream = new MemoryStream();
document.Save(stream, SaveFormat.Pdf);
File.WriteAllBytes("…/…/doc/test.pdf", stream.ToArray());

That’s why I maybe thought that you found a specific element in the document attached in the test application that triggered the error.

Hi Simon,

Thanks for your inquiry.

We have logged a separate issue WORDSNET-14935 to address this problem. Our product team will further look into the details of this problem and we will keep you updated on the status of this issue.

We have also asked the ETA of this issue from our product team and will update you as soon as any estimates are available.

We apologize for your inconvenience.

Can you please also try running the following code (with Aspose.Words for .NET 17.2.0*) to see if removing the Visio Drawing on 5th page of “Brugervejledning.docx” prevents the exception on your test environment?

Document doc = new Document(MyDir + @"Brugervejledning.docx");
foreach (Shape s in doc.GetChildNodes(NodeType.Shape, true))
{
    if (s.OleFormat != null)
    {
        if (s.OleFormat.ProgId.Equals("Visio.Drawing.11"))
            s.Remove();
    }
}
doc.Save(MyDir + @"17.2.0.pdf");

Best regards,

Hi Simon,

Regarding WORDSNET-14935, I am afraid, we could not reproduce the issue (a generic error occurred in GDI+) on our end and hence we have only following workaround.

As a workaround please try to use DmlEffectsRenderingMode.None or DmlEffectsRenderingMode.Fine to avoid the problem. Hope, this helps.

Best regards,