简体   繁体   English

我应该安装哪些库才能在基于 Alpine 的图像中的 ASP NET Core 应用程序中使用 System.Drawing.Common

[英]Which libraries should I install for work with System.Drawing.Common in ASP NET Core application inside Alpine-based image

I have the following code in dotnet core 3.0 application:我在 dotnet core 3.0 应用程序中有以下代码:

...
// This url returns image (Content-Type: Blob)
var imageUrl = "https://barcode.tec-it.com/barcode.ashx?data=ABC-abc-1234&code=Code128&dpi=96";
HttpClient client = HttpClientFactory.Create();
using (var input = await client.GetStreamAsync(imageUrl))
{
    var bitmap = new Bitmap(input); // this is dangerous code
}
...

I want to run this code inside docker container, which based on alpine3.9 (mcr.microsoft.com/dotnet/core/aspnet:3.0.0-alpine3.9) I know that I should install additional libraries inside docker container for working with System.Drawing.Common:我想在 docker 容器中运行此代码,该容器基于 alpine3.9 (mcr.microsoft.com/dotnet/core/aspnet:3.0.0-alpine3.9) 我知道我应该在 docker 容器中安装其他库才能工作使用 System.Drawing.Common:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.0.0-alpine3.9
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
    && apk update \
    && apk add \
        libgdiplus

But anyway - it fails with the following stacktrace:但无论如何 - 它失败了以下堆栈跟踪:

System.ArgumentException: Parameter is not valid.
   at System.Drawing.Image.InitializeFromStream(Stream stream)
   at System.Drawing.Bitmap..ctor(Stream stream)

I know that this code works fine inside debian-based container which I cook like this:我知道这段代码在我这样烹制的基于 debian 的容器中运行良好:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.0
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
    libgdiplus

I tried to install libgdiplus-dev , fontconfig and ttf-dejavu libraries inside alpine container but it doesn't works我试图在 alpine 容器中安装libgdiplus-devfontconfigttf-dejavu库,但它不起作用

So the main question - is it libraries related issue or bug inside dotnet?所以主要问题 - 是与库相关的问题还是 dotnet 中的错误? If first - what libraries should I install for this to work?如果首先 - 我应该安装哪些库才能使其工作?

TL;DR TL;博士

change https://barcode.tec-it.com/barcode.ashx?data=ABC-abc-1234&code=Code128&dpi=96 to https://www.scandit.com/wp-content/themes/scandit/barcode-generator.php?symbology=code128&value=213214214&size=200&ec=Lhttps://barcode.tec-it.com/barcode.ashx?data=ABC-abc-1234&code=Code128&dpi=96更改为https://www.scandit.com/wp-content/themes/scandit/barcode-generator.php?symbology=code128&value=213214214&size=200&ec=L

DESCRIPTION描述

It is bug inside dotnet - https://github.com/dotnet/corefx/issues/41527 Issue link generates GIF - it causes issue.这是 dotnet 内部的错误 - https://github.com/dotnet/corefx/issues/41527问题链接生成 GIF - 它会导致问题。 Workaround - use link which will generates JPEG解决方法 - 使用将生成 JPEG 的链接

For me the following modification of dockerfile worked (.net core 3.1).对我来说,dockerfile 的以下修改有效(.net core 3.1)。 Pay attention that libgdiplus, libc-dev and libx11-dev are added to the runtime:注意 libgdiplus、libc-dev 和 libx11-dev 添加到运行时:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine3.12 as builder
WORKDIR /app
COPY nuget.config nuget.config

RUN apk update
RUN apk add --update nodejs nodejs-npm

RUN cd XXX.XXXXXXX.YYYYYY && dotnet restore --configfile ../nuget.config && 
dotnet publish -c Release -o ../out/

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine3.12
WORKDIR /app

# Alpine 3.x Docker images no longer have tzdata package 
RUN apk update && \
apk add --no-cache tzdata

RUN apk add libgdiplus --repository https://dl-3.alpinelinux.org/alpine/edge/testing/
RUN apk add libc-dev libx11-dev

COPY --from=builder /app/out .
CMD ["dotnet", "XXX.XXXXXXX.YYYYYY"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .NET Core System.Drawing.Common PrintDocument在Linux上不起作用 - .NET Core System.Drawing.Common PrintDocument doesn't work on Linux 如何在使用“.NETFramework,Version=v4.5.2”的项目中安装 System.Drawing.Common? - How do I install System.Drawing.Common in a project that uses '.NETFramework,Version=v4.5.2'? 使用 C#.net5.0 但没有 System.Drawing.Common 获取/设置图像文件的分辨率? - Get/set the resolution of an image file using C# net5.0 but without System.Drawing.Common? IronPDF 对 System.Drawing.Common 的依赖 - IronPDF dependency on System.Drawing.Common System.Drawing.Common 不适用于 Windows - System.Drawing.Common not working on Windows 错误系统绘制常见的Asp.Net Core - Error System Drawing Common Asp.Net Core .NET System.Drawing.Common 4.5.1 的 NuGet 包包含不正确的程序集版本 - NuGet package for .NET System.Drawing.Common 4.5.1 contains incorrect version of assemblies 错误 NU1100:无法为“net6.0”解析“HtmlAgilityPack (>= 1.11.45)”和“System.Drawing.Common (>= 6.0.0)” - error NU1100: Unable to resolve 'HtmlAgilityPack (>= 1.11.45)' and 'System.Drawing.Common (>= 6.0.0)' for 'net6.0' .NET 6/7 从 System.Drawing.Common 迁移到 Microsoft.Maui.Graphics - .NET 6/7 Migration from System.Drawing.Common to Microsoft.Maui.Graphics System.drawing.common 'gdip' 的类型初始值设定项抛出异常 - System.drawing.common the type initializer for 'gdip' threw an exception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM