Azure Function gives error: System.Drawing is not supported on this platform
Azure Function gives error: System.Drawing is not supported on this platform
(如果这个问题措辞不当,有人可以帮我解决一下吗?)
我有一个 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.
据我所知,System.Drawing.Common 现在在 .NET Core 上受支持,我相信这是我的 Azure Function 所处的环境 运行。不过,实际项目是 .NET Standard 2.0 项目。
我很困惑如何解决这个问题。我尝试将项目转换为 .NET Core 2.1 项目,但这导致了与 "Metadata generation failed" 相关的奇怪错误,并且无法找到 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 Functions 切换到 v3:
在函数应用程序设置面板 -> 运行时版本 ~3
使用此设置,您的代码 运行 在支持 Core 3 的沙箱中,(您不需要将 dll 重建为 Core3,我 运行 我的 .net core 2.1 dll 没有错误),令人惊讶的是...您不再遇到此异常:
System.Drawing.Common: 此平台不支持 System.Drawing。
因为 CLI 可以在子系统中找到需要的 GDI/GDI+。
现在我可以将 html 转换为 pdf 而不会发疯。
(如果这个问题措辞不当,有人可以帮我解决一下吗?)
我有一个 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.
据我所知,System.Drawing.Common 现在在 .NET Core 上受支持,我相信这是我的 Azure Function 所处的环境 运行。不过,实际项目是 .NET Standard 2.0 项目。
我很困惑如何解决这个问题。我尝试将项目转换为 .NET Core 2.1 项目,但这导致了与 "Metadata generation failed" 相关的奇怪错误,并且无法找到 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 Functions 切换到 v3: 在函数应用程序设置面板 -> 运行时版本 ~3
使用此设置,您的代码 运行 在支持 Core 3 的沙箱中,(您不需要将 dll 重建为 Core3,我 运行 我的 .net core 2.1 dll 没有错误),令人惊讶的是...您不再遇到此异常:
System.Drawing.Common: 此平台不支持 System.Drawing。
因为 CLI 可以在子系统中找到需要的 GDI/GDI+。 现在我可以将 html 转换为 pdf 而不会发疯。