Converter.ConvertMHTML throws System.PlatformNotSupportedException: System.Drawing.Common is not supported on this platform in Linux container

Here is the stacktrace:

anzen_server       |       IndexWorker: Unexpected exception while indexing Document with Id '0046b904-9a1f-47bb-b2df-2098dc51c5fa': System.PlatformNotSupportedException: System.Drawing.Common is not supported on this platform.
anzen_server       |          at System.Drawing.Drawing2D.Matrix..ctor(Single m11, Single m12, Single m21, Single m22, Single dx, Single dy)
anzen_server       |          at Aspose.Html.Rendering.Pdf.PdfDevice.BeginPage(SizeF size)
anzen_server       |          at ♥   .☻      ☻(IDevice ☻)
anzen_server       |          at ♣   .☼​     ☻(Renderer ☻, ♣   [] ♥, IDevice ♣, TimeSpan)
anzen_server       |          at Aspose.Html.Rendering.MhtmlRenderer.☻(IDevice ☻, Configuration ♥, TimeSpan ♣, Stream[])
anzen_server       |          at Aspose.Html.Rendering.MhtmlRenderer.Render(IDevice device, Stream document, Configuration configuration, TimeSpan timeout)
anzen_server       |          at Aspose.Html.Rendering.MhtmlRenderer.Render(IDevice device, Stream document, Configuration configuration)
anzen_server       |          at ♠  .☻(♥   ☻, IDevice ♥)
anzen_server       |          at ♠  .♥     ☻(♥   ☻, PdfSaveOptions ♥, ICreateStreamProvider ♣)
anzen_server       |          at ♠  .♥     ☻(♥   ☻, PdfSaveOptions ♥, String ♣)
anzen_server       |          at Aspose.Html.Converters.Converter.ConvertMHTML(Stream stream, PdfSaveOptions options, String outputPath)

Is there a special version for Linux? I’ve already special versions for Aspose.PDF and Aspose.Imaging :wink:


Would you kindly share a bit more details like sample input document, code snippet, and docker file? We will log an investigation ticket and rectify this issue.

This happens with every mhtml I convert to an PDF.
The Mhtml is created by Apose.HTML itsself from an *.eml or *.msg-File.
I’m using .NET 7 for this.

I will try if I can put together an example for you.


Please take your time to put together an example and share it with us. We will log an issue in our issue tracking system and share the ID with you.

I have build a little example complete with Dockerfile and docker compose. Just extract it and execute
“docker-compose up” which will build the VS solution and executes the container.

It will run on Windows without problems, but will give the exception “The type initializer for ‘Gdip’ threw an exception.” on Linux, which is a new exception to me. (180.1 KB)


We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): HTMLNET-4250

You can obtain Paid Support services if you need support on a priority basis, along with the direct access to our Paid Support management team.

1 Like


The current version does not support Net 7 on Linux. But we are preparing to add Net 7 support on Linux and a new Drawing system in Q2 2023.

That’s nice but it fails also on .NET 6.
I’ve attached you the same example as a .NET 6 solution and docker container.

20230124_Mhtml_Linux_Fails (19.8 KB)


Try to set a specific folder for fonts and put the necessary fonts there:

public void Test()
    string[] fontsFolders = { "/fontFolder/" };

    var configuration = new Configuration();
    var userAgentService = configuration.GetService<IUserAgentService>();
    userAgentService.FontsSettings.SetFontsLookupFolders(fontsFolders, true);

You can also process the selection of fonts and substitute a specific font:

    configuration.GetService<IUserAgentService>().FontsSettings.FontMatcher = new ArialFontMatcher();

    using (HTMLDocument doc = new HTMLDocument(source, "", configuration))
private class ArialFontMatcher : FontMatcher
     private readonly byte[] font;

     public ArialFontMatcher()
          font = File.ReadAllBytes(fontsFolders[0] + "arial.ttf");

     public override byte[] MatchFontFallback(FontMatchingProperties fontMatchingProperties, uint charCode)
          return font;

Please have a look at my solution: I do not want to open the HTML, I want to convert it to PDF with
Aspose.Html.Converters.Converter.ConvertMHTML(htmlStream, pdfSaveOptions, tempFileNamePdf);
which has no option for a font folder.

Also an exception is occuring within the Converter.ConvertMHTML() call which has nothing to do with fonts.

The exception is:
aspose_mhtml | Unhandled exception. System.TypeInitializationException: The type initializer for ‘Gdip’ threw an exception.
aspose_mhtml | —> System.DllNotFoundException: Unable to load shared library ‘libdl’ or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibdl: cannot open shared object file: No such file or directory


We have updated the ticket information accordingly and will let you know once we make some further updates regarding its resolution.


To fix these errors, try the following steps:

  1. Install the nuget package System.Drawing.Common version 6.0. in the solution.
  2. Add the following option to the .proj file:
<ItemGroup> <RuntimeHostConfigurationOption Include="System.Drawing.EnableUnixSupport" Value="true" /> </ItemGroup>
  1. Add the following steps to Dockerfile to install libgdiplus:
RUN apt-get update RUN apt-get install -y --allow-unauthenticated \ libc6-dev \ libgdiplus \ libx11-dev ENTRYPOINT ["dotnet", "20230124_Mhtml_Linux_Fails.dll"]
  1. Rebuild the container.

Installing libgdiplus fails with this error:

[includenode 7/11] RUN apt-get install -y --allow-unauthenticated libc6-dev libgdiplus libx11-dev:
#0 0.538 Reading package lists…
#0 1.125 Building dependency tree…
#0 1.301 Reading state information…
#0 1.308 E: Unable to locate package libc6-dev
#0 1.308 E: Unable to locate package libgdiplus
#0 1.308 E: Unable to locate package libx11-dev

failed to solve: executor failed running [/bin/sh -c apt-get install -y --allow-unauthenticated \ libc6-dev \ libgdiplus \ libx11-dev]: exit code: 100
PS C:\Work\Anzen\Aspose.Total\20230124_Mhtml_Linux_Fails NET6>

Do I need to configure an additional apt-source?


It looks like a problem installing packages. You can please try configuring another apt-source and if problem still persists, please let us know.

Problem were the pasted backslashes from your example. I removed them and the install block of the Dockerfile runs now smoothly.

My example does run now in the Ubuntu container with .NET6, but not with .NET 7. Maybe you should extend your product documentation with these steps?

Do you know when the .NET7 version will be released?


It is nice to know that things have been sorted out now.

As shared earlier, the current version does not support Net 7 on Linux. But we are preparing to add Net 7 support on Linux and a new Drawing system in Q2 2023.

Sure, we will update the documentation accordingly soon.


We just tried in .NET 7 and noticed that the earlier suggested solution also works in .NET 7 environment from your example. Can you please check again and confirm?

Yes it will work in my supplied example if I downgrade System.Drawing.Common to Version 6.0.0.
But for my complete solution I have also to downgrade many more .NET Libraries from 7.0.0 to 6.0.0 because of dependencies and I’m not aware how compatible this is or if this is causing other failures.


Thanks for the feedback. We will keep working on the ticket and let you know as soon as its resolved.