Azure Web App 中的库错误(Linux 上的 Net Core)



我正在开发一个使用.Net Core和Microsoft Azure作为托管的Web应用程序。

今天,我添加了这段代码,在我的PC上可以完美运行:

try {
using (var bitmap = new System.Drawing.Bitmap(postedFile.OpenReadStream())) { }
} catch (Exception e) {
Logger.LogError(e.ToString());
return false;
} finally {
postedFile.OpenReadStream().Position = 0;
}

但是在Azure上,它给出了这个例外(感谢Logger.LogError(:

System.TypeInitializationException: The type initializer for 'Gdip' threw an exception.
---> System.DllNotFoundException: Unable to load shared library 'libgdiplus' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibgdiplus: cannot open shared object file: No such file or directory
at System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& token, StartupInput& input, StartupOutput& output)
at System.Drawing.SafeNativeMethods.Gdip..cctor()
--- End of inner exception stack trace ---
at System.Drawing.SafeNativeMethods.Gdip.GdipLoadImageFromDelegate_linux(StreamGetHeaderDelegate getHeader, StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, StreamCloseDelegate close, StreamSizeDelegate size, IntPtr& image)
at System.Drawing.Image.InitializeFromStream(Stream stream)
at System.Drawing.Bitmap..ctor(Stream stream)
at PushMeWebServer.Utils.FileUploadCheckHelper.IsImage(IFormFile postedFile) in D:DownloadsWorkspaceVisualStudioPushMe_codePushMeWebServerPushMeUtilsFileUploadCheckHelper.cs:line 71

我尝试使用 SSH 安装一些缺少的库,例如 libc6-dev libgdiplus libx11-dev,但我没有解决它。为什么?这是我第一次体验这种环境,所以我不是专家

是将 .NET Core 应用程序作为独立的控制台应用运行,还是使用 Azure Functions 核心工具运行它?我怀疑这是由于 Azure 应用服务的沙盒限制:

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

最新更新