在Azure Webapp上发生了GDI+的通用错误。

3

我正在使用spire库为用户创建PDF文件。

    string userId = User.Identity.GetUserId();
        User trainee = _userDAL.GetUserByIdentityId(userId);

        // Get the Employee scores
        string fileNameTemplate = Server.MapPath(Url.Content("~/assets/cert1-{0}-{1}.docx"));
        string nnn = string.Format("cert1-{0}-{1}.pdf", trainee.StaffID, DateTime.Now.Millisecond);
        string serverPath = MainConfig.P_EXPORT;
        var folder = Server.MapPath(serverPath);

使用(Document document_test = new Document())创建一个新的文档对象,然后通过document_test.LoadFromFile(fileNameTemplate)方法加载指定文件名的模板。

            //Update Text of Title
            document_test.Replace("#trainee_name#", trainee.Name, false, true);
            document_test.Replace("#course_name#", "Test", false, true);
            document_test.Replace("#date_info#", DateTime.Today.ToShortDateString(), false, true);

            document_test.SaveToFile(nnn, Spire.Doc.FileFormat.PDF, System.Web.HttpContext.Current.Response, HttpContentType.Attachment);
        }

代码在本地开发机器上运行完美,但是当我将其上传到Azure Web应用程序时,出现了这个通用错误:GDI+中发生了一个通用错误。
堆栈跟踪:
[ExternalException (0x80004005): GDI+ 中发生了一个通用错误。] System.Drawing.Imaging.Metafile..ctor(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, String description) +226801 System.Drawing.Imaging.Metafile..ctor(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type) +34 sprᲦ.ᜀ(PageSetup A_0, ImageType A_1, MemoryStream A_2, Int32 A_3, GraphicsUnit A_4) +255 sprᲦ.ᜀ(PageSetup A_0, ImageType A_1, MemoryStream A_2, Int32 A_3) +19 sprᲦ.᜔() +224 sprᲦ.ᜁ(IDocument A_0) +234 spr᧤.ᜀ(Document A_0) +93 Spire.Doc.Document.ᜀ(Stream A_0) +94 Spire.Doc.Document.SaveToFile(Stream stream, FileFormat fileFormat) +289 Spire.Doc.Document.SaveToFile(String fileName, FileFormat fileFormat, HttpResponse response, HttpContentType contentType) +673 LMSv1.Controllers.DisplayController.DownloadCertification(Nullable1 tid, Nullable1 eid) +616 lambda_method(Closure , ControllerBase , Object[] ) +146 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +167 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +27 System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22 System.Web.Mvc.Async.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult) +29 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49

你找到这个问题的替代方案了吗? - Yogesh
不,我必须依赖另一台服务器来生成所需的文件,然后从那里下载它们。 - wandos
4个回答

3

是的,这正是发生的事情,我不得不使用另一台服务器来利用DGI+,然后将信息传输回Azure。如果您发现更好的方法,请告诉我。 - wandos
微软在Azure Web应用程序中有没有任何替代解决方案?还是他们说从现在开始不再支持图像处理? - Yogesh

2
似乎这个问题已经通过使用以下代码解决。请参见类似的帖子和解决方案这里
Document doc = new Document();
doc.LoadFromFile(fileName);
ToPdfParameterList tpl = new ToPdfParameterList{

    UsePSCoversion = true;           
    //azure          
};  
doc.SaveToFile(resultName);

0
粗略猜测:您可能在隐式引用另一个已安装在GAC中或未设置为本地复制的dll。因此,尽管您的大部分编译代码已部署到Azure,但涉及到的神秘dll并没有被部署到Azure上。

我已经检查了 Azure Web 应用程序上的 bin 文件夹,dll 文件在那里。 - wandos

0

e-iceblue?是指Spire.PDF和Spire.Doc这个DLL在Azure Web应用程序中不受支持。 - Yogesh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接