Azure 函数给出错误:此平台不支持 System.Drawing [英] Azure Function gives error: System.Drawing is not supported on this platform

查看:34
本文介绍了Azure 函数给出错误:此平台不支持 System.Drawing的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(如果这个问题措辞不好,有人可以帮我澄清一下吗?)

(If this question is poorly worded, could someone please help me clear it up?)

我有一个依赖于一些 System.Drawing 代码的 Azure 函数 (2.0).我添加了对 System.Drawing.Common (4.5.0) 的 NuGet 引用.

I have an Azure Function (2.0) which relies on some System.Drawing code. I've added a NuGet reference to System.Drawing.Common (4.5.0).

然而,发布应用程序后,当调用该函数时,会产生错误:

After publishing the app, however, when the function is called, it produces the error:

System.Private.CoreLib:执行函数时出现异常:[我的功能名称].System.Drawing.Common:System.Drawing 不是本平台支持.

System.Private.CoreLib: Exception while executing function: [MyFunctionName]. System.Drawing.Common: System.Drawing is not supported on this platform.

据我所知,System.Drawing.Common 现在在 .NET Core 上受支持,我相信这是运行 Azure Function 的环境.不过,实际项目是 .NET Standard 2.0 项目.

As far as I'm aware, System.Drawing.Common is supported on .NET Core now, which I believe is the environment in which my Azure Function is running. The actual project is a .NET Standard 2.0 project, though.

我对如何解决这个问题感到困惑.我已经尝试将项目转换为 .NET Core 2.1 项目,但这导致了与元数据生成失败"和无法找到 System.Runtime 相关的奇怪错误.

I am confused as to how to resolve this. I've tried converting the project to a .NET Core 2.1 project but that led to bizarre errors related to "Metadata generation failed" and an inability to find System.Runtime.

如果相关,我的项目会引用 Microsoft.Azure.WebJobs.Extensions.EventGrid (2.0.0-beta2).

My project references Microsoft.Azure.WebJobs.Extensions.EventGrid (2.0.0-beta2) if that's relevant.

推荐答案

这不是关于 CLR,而是关于 沙箱.

It's not about the CLR, it's about the sandbox.

System.Drawing 严重依赖 GDI/GDI+ 来完成它的工作.由于这些 API 具有一定的风险性(大型攻击面),因此它们在应用服务沙箱中受到限制.

System.Drawing relies heavily on GDI/GDI+ to do its thing. Because of the somewhat risky nature of those APIs (large attack surface) they are restricted in the App Service sandbox.

为了彻底减少攻击面,沙箱阻止了几乎所有的 Win32k.sys API 被调用,这实际上意味着大部分 User32/GDI32 系统调用都被阻止了.对于大多数应用程序这不是问题,因为大多数 Azure Web 应用程序不需要访问 Windows UI 功能(毕竟它们是 Web 应用程序).

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.

Try to find an different library that doesn't rely on System.Drawing/GDI, like ImageSharp.

这篇关于Azure 函数给出错误:此平台不支持 System.Drawing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆