【问题标题】:Dockerized Dotnet Core 2.1 throws Gdip exception when using Select.HtmlToPdf.NetCoreDockerized Dotnet Core 2.1 在使用 Select.HtmlToPdf.NetCore 时抛出 Gdip 异常
【发布时间】:2019-02-03 19:11:37
【问题描述】:

我在 Dotnetcore 2.1 中使用 Select.HtmlToPdf.NetCore(18.3.0) 将 Html 转换为 pdf。它在本地环境中完美运行,但使用 Docker 托管时会抛出错误提示,

{"fileName":"System.TypeInitializationException: 类型初始化器 对于 'Gdip' 抛出异常。 ---> System.DllNotFoundException: 无法加载共享库“libdl”或其依赖项之一。在 为了帮助诊断加载问题,请考虑设置 LD_DEBUG 环境变量:liblibdl:无法打开共享对象文件:否 此类文件或目录\n 在 Interop.Libdl.dlopen(String fileName, Int32 标志)\n 在 System.Drawing.SafeNativeMethods.Gdip.LoadNativeLibrary()\n at System.Drawing.SafeNativeMethods.Gdip..cctor()\n --- 内部结束 异常堆栈跟踪 ---\n at System.Drawing.SafeNativeMethods.Gdip.GdipNewPrivateFontCollection(IntPtr& fontCollection)\n 在 SelectPdf.Lib.ᡜ..ctor()\n 在 SelectPdf.Lib.៞..ctor()\n 在 SelectPdf.Lib.៞..ctor(ᡏ A_0, ᠝ A_1)\n
在 SelectPdf.HtmlToPdf.ᜁ(字符串 A_0,字符串 A_1,字符串 A_2,字符串 A_3,布尔 A_4)\n 在 SelectPdf.HtmlToPdf.ConvertHtmlString(String htmlString)

我尝试在 Dockerfile 中添加这些行,但仍然出现相同的错误。

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base  
RUN apt-get update  
RUN apt-get install -y apt-utils  
RUN apt-get install -y libgdiplus  
RUN ln -s /usr/lib/libgdiplus.so /usr/lib/gdiplus.dll  
WORKDIR /app  
EXPOSE 80  

【问题讨论】:

  • 您是否尝试在基于 Windows 或 Linux 的引擎上进行托管?
  • 我都试过了。对我没有用。
  • 在 github 上查看这个未解决的问题:github.com/dotnet/corefx/issues/25102
  • 谢谢莫辛。我已经按照这些步骤进行了操作,但没有帮助。我已经向 Select.HtmlToPdf.NetCore 的所有者提出了这个问题。

标签: docker .net-core


【解决方案1】:

我知道这是一个老问题,但我最近遇到了这个问题,我想分享一下我的解决方案。
Select.HtmlToPdf.NetCore 不适用于 linux
只是不要。如果您已经使用 html 生成字符串,我建议您找到这个 nuget:Haukcode.DinkToPdf
要查找一些教程,只需 google DinkToPdf。 Haukcode 刚刚更新,并且对 docker 更友好。
一些 dockerfile 的东西:
FROM microsoft/aspnetcore:2.0.0 as Base RUN apt-get update RUN apt-get install -y apt-utils RUN apt-get install -y libgdiplus RUN apt-get install -y libc6-dev RUN ln -s /usr/lib/libgdiplus.so/usr/lib/gdiplus.dll ... 我希望它会对某人有所帮助:)

【讨论】:

  • 我按照此处列出的解决方案并使其正常工作:github.com/dotnetcore/NPOI/issues/148 类似,但缺少 X-Server 的显示设置
  • 我也遇到了同样的问题,但解决方案对我不起作用,因为我在构建阶段而不是在发布阶段添加了 all install 命令。对于多阶段 docker 文件,应在发布阶段添加安装命令。
【解决方案2】:

这对我有用。 我正在运行 Debian 服务器,使用 System.Drawing.Common 4.7.0

RUN apt-get update \
&& apt-get install -y --allow-unauthenticated \
    libc6-dev \
    libgdiplus \
    libx11-dev \
 && rm -rf /var/lib/apt/lists/*

【讨论】:

    【解决方案3】:

    您需要在 Docker 容器中安装 libc6-dev。您可以通过运行以下命令来安装 libc6-dev:

    RUN apt-get install -y libc6-dev
    

    让我知道这是怎么回事。

    【讨论】:

    • 在我的问题中,我提到上述命令对我不起作用。谢谢你的回答。
    • 抱歉,您需要安装 libc6-dev。你能试试吗?我已经更新了答案。
    • 对不起。仍然有同样的错误。感谢您的帮助。
    • 安装 libc6-dev 让我摆脱了 Dll 加载异常。但现在我对 kernel32.dll 有同样的例外
    • 你能分享完整的堆栈跟踪吗?另外,如果添加 libc6-dev 有帮助,你能支持这个答案吗?谢谢! :)
    【解决方案4】:

    我在使用 iTextSharp 5.5.13.1 时也遇到了同样的问题,我解决的方法是在我的 Dockerfile 中结合@Frederik Carlier 的解决方案:

    RUN apt-get update && apt-get -y install libxml2 libgdiplus libc6-dev
    

    之后,我重新启动了 Rancher Container 和 Rancher User Stack,它工作正常。

    (使用的运行时:FROM microsoft/dotnet:2.2-aspnetcore-runtime)

    【讨论】:

      猜你喜欢
      • 2020-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-09
      • 1970-01-01
      • 2023-03-13
      • 2013-05-24
      • 1970-01-01
      相关资源
      最近更新 更多