asp.net-mvc - asp.net中奇怪的图像生成错误

标签 asp.net-mvc iis png

我有一个 ASP.NET-MVC 项目,我需要在其中动态生成一些 png 图像。这很容易。我只是创建返回 FileSreamResult 对象的 ActionResult。为了生成图像,我使用了 System.Drawing 中的类,例如 Bitmap 和 Image。在本地机器和生产服务器上一切正常。但是当生产服务器上的 IIS 由于不活动而关闭我的应用程序池并再次启动它时,图像生成开始失败。

问题在于尝试将图像保存到流的代码中:

  var imageStream = new MemoryStream();
  bmp.Save(imageStream, ImageFormat.Png);

异常是:System.Runtime.InteropServices.ExternalException (0x80004005):GDI+ 中发生一般错误。所以没有太大帮助。我尝试了不同的解决方案,但没有任何帮助。找到这个话题后Alternatives to System.Drawing for use with ASP.NET?

本主题的主要思想是:

Classes within the System.Drawing namespace are not supported for use within a Windows or ASP.NET service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions.



所以我决定使用 WPF 类来生成图像。我重写了所有图像生成代码,但现在在应用程序池重新启动后出现另一个错误。异常(exception):
System.Runtime.InteropServices.COMException (0x88982F8A):来自 HRESULT 的异常:0x88982F8A。当我尝试将 PngBitmapEncoder 保存到流式传输时会发生这种情况
var stream = new MemoryStream();
encoder.Save(stream);

也许有人遇到过这个问题或只是有任何想法?

最佳答案

这是一个不满意的答案...

当我第一次部署新的图像生成功能时,我遇到了同样的错误。

我停止了相应的应用程序池,再次重新启动它,它工作。

关于asp.net-mvc - asp.net中奇怪的图像生成错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9631170/

相关文章:

iis - 是否可以同时运行 IIS 和 Tomcat?

asp.net - IIS 7.5 基于域名的 URL 重写

caching - IIS7 是否缓存视频(mp4/wmv)文件?

css - 在 CSS 中为 PNG 图像投影

image - OpenCV : Transparent area of imported . png 文件现在是白色的

c# - WebApi Controller 中使用 SimpleInjector 的运行时空引用异常

asp.net-mvc - 安装 Oracle Developer Tools for Visual Studio 2017 时出错

asp.net-mvc - 默认 MVC 项目中的两个 Web.Config 文件

c# - 检测到 ASP.NET MVC 5 危险的 Request.Path

css - IE6 PNG 透明 CSS hack 不起作用