(如果这个问题措辞不好,有人可以帮我解决吗?)
我有一个 Azure Function (2.0),它依赖于一些 System.Drawing 代码。我添加了对 System.Drawing.Common (4.5.0) 的 NuGet 引用。
但是,发布应用程序后,调用该函数时,会产生错误:
System.Private.CoreLib: Exception while executing function: [MyFunctionName]. System.Drawing.Common: System.Drawing is not supported on this platform.
据我所知,.NET Core 现在支持 System.Drawing.Common,我相信这是我的 Azure Function 运行的环境。不过,实际项目是 .NET Standard 2.0 项目。
我很困惑如何解决这个问题。我尝试将项目转换为 .NET Core 2.1 项目,但这导致了与“元数据生成失败”相关的奇怪错误,并且无法找到 System.Runtime。
我的项目引用了 Microsoft.Azure.WebJobs.Extensions.EventGrid (2.0.0-beta2)(如果相关)。
最佳答案
这不是关于 CLR,而是关于 sandbox .
System.Drawing 严重依赖 GDI/GDI+ 来完成其工作。由于这些 API 具有一定的风险性(攻击面较大),因此它们在应用服务沙箱中受到限制。
Win32k.sys (User32/GDI32) Restrictions
For the sake of radical attack surface area reduction, the sandbox prevents almost all of the Win32k.sys APIs from being called, which practically means that most of User32/GDI32 system calls are blocked. For most applications this is not an issue since most Azure Web Apps do not require access to Windows UI functionality (they are web applications after all).
尝试找到一个不依赖于 System.Drawing/GDI 的不同库,例如 ImageSharp .
关于Azure Function 给出错误 : System. 此平台不支持绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51904125/