Error converting docx to png in .Net 6 on Linux in versions 22.1 and 22.2

Hello, I have recently upgraded my .Net project from Core 3.1 to .Net 6, and my GroupDocs.Conversion version from 20.9.3 to 22.2. I also switched my OS from Windows to Linux, which meant I had to start including libgdiplus in my install

Both 22.1 and 22.2 are working fine in all scenarios but one: Converting DOCX to PNG throws an error:

Unhandled Exception: GroupDocs.Conversion.Exceptions.GroupDocsConversionException: The type initializer for ’ threw an exception.
at #002#005#003.#002()
at GroupDocs.Conversion.Converter.#002()
at GroupDocs.Conversion.Converter.Convert(SaveDocumentStream document, ConvertedDocumentStream documentCompleted, ConvertOptions convertOptions)

Converting from DOCX to PDF works fine - the error is only for pngs.

I believe this is the same issue this post except for PNGs instead of PDFs:

This makes sense as the PDF issue was apparently fixed in version 21.11 under the following id:

CONVERSIONNET-4894

What other information do you need?

1 Like

Just to be clear all other document types are converting to PNG, including Excel and PowerPoint. The only one having the issue is DOCX

@dallen3xerox

Please share following details and we’ll investigate this issue:

  • DOCX to PNG conversion code
  • Development environment details (e.g. OS name/version)
  • Source/problematic file(s)

Make sure you configured/installed libgdiplus like this:

apt-get update
apt-get install -y libgdiplus
apt-get install -y ttf-mscorefonts-installer fontconfig
  • DOCX to PNG conversion code:

      public override async Task<Stream> ConvertToThumbnailAsync(Stream source, int width, int height)
      {
          Stream thumbnailStream = null;
          
          using (Converter converter = new Converter(() => source))
          {
              thumbnailStream = new MemoryStream();
    
              var options = new ImageConvertOptions
              {
                  Format = ImageFileType.Png,
                  PageNumber = 1,
                  PagesCount = 1,
                  Height = height
              };
    
              converter.Convert(() => new MemoryStream(), (convertedStream, x) =>
              {
                  convertedStream.CopyTo(thumbnailStream);
              }, options);
          }
    
          return await Task.FromResult(thumbnailStream);
      }
    
  • Development environment details

Amazon Linux 2 version 2.2.11

  • Source/problematic file(s)

I don’t think this error has anything to do with the specific file, but here are a few that fail:

qbf.docx (11.7 KB)
Welcome to Word.docx (1.3 MB)

  • Make sure you configured/installed libgdiplus like this

This is not Ubuntu. There is no apt-get and there is no yum package called ttf-mscorefonts-installer. What’s the alternative for Amazon Linux? (which I think is redhat. I don’t usually work with Linux)

1 Like

@dallen3xerox

This issue is logged in our internal issue tracking system with ticket ID CONVERSIONNET-5146. You’ll be notified in case of any progress update.

By the way, we have since changed our environment back to Windows, but the problem exists there as well

@dallen3xerox

On Windows, you are trying to convert the Word file to PNG using .NET 6 app? Could you please share a simple console application using that issue could be reproduced?

Hi Atir, I apologize. I got to the root of the problem when I tried to reproduce it in a console app. It turns out that we were including an old version of libSkiaSharp.dll in our project output. It took me 2 days to find it, but once it was removed everything worked fine. Thank you for your help!

@dallen3xerox

Good to know that the issue is fixed.