Azure Function 给出错误 : System. 此平台不支持绘图

标签 azure .net-core azure-functions .net-standard azure-functions-runtime

(如果这个问题措辞不好,有人可以帮我解决吗?)

我有一个 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/

相关文章:

json - 在 VS 2017 Azure Function 开发中从 local.settings.json 读取值

azure - 无法从 Function App 向 Azure 服务总线发送消息

azure - 如何重新触发 Azure Cosmos DB 中的 CosmosDBTrigger 事件或在处理事件时出现异常时获取触发的事件

适用于现有 Azure 基础设施的 Azure 登陆区

javascript - Azure 服务总线计划消息 "in"绑定(bind)未定义

azure - 如何使用 Node.js 在 MSAL 的帮助下获取 Azure DevOps PAT 列表

c# - .NET Core 3.0 声明转换

c# - AWS SQS,如何计算消息属性的 MD5 消息摘要

c# - 如何在 .NET Core 中撤消 Entity Framework Update-Database

azure - 如何更改已创建和部署的 Azure IoT 中心的 TLS 版本?