wandos
wandos

Reputation: 1619

A generic error occurred in GDI+. on Azure Webapp

I am using spire lib to create pdf files for the user.

    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);

using (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);
        }

The Code works perfectly on the local development machine, but when i upload it to Azure web app i get a this generic error: A generic error occurred in GDI+.

Stack Trace:

[ExternalException (0x80004005): A generic error occurred in 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

Upvotes: 3

Views: 3036

Answers (4)

vaalex
vaalex

Reputation: 109

It seems that this issue have already been resolved by using the following code. See the similar post and solution here.

Document doc = new Document();
doc.LoadFromFile(fileName);
ToPdfParameterList tpl = new ToPdfParameterList{

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

Upvotes: 2

David Ebbo
David Ebbo

Reputation: 43203

The sandbox that Azure Web Apps run under has some restrictions which blocks certain calls, which is likely what you're running into with GDI+.

You can find more information about those sandbox restrictions on https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#win32ksys-user32gdi32-restrictions.

Upvotes: 3

robrich
robrich

Reputation: 13205

Another stab-in-the-dark guess: maybe check the docs at http://www.e-iceblue.com/Introduce/free-pdf-component.html to see if there are any known issues when running in Azure.

Upvotes: 0

robrich
robrich

Reputation: 13205

Rough guess: you're implicitly referencing another dll either installed in the GAC or not set to copy local. Thus though the majority of your compiled code is deployed to Azure, the mystery dll in question isn't deployed to azure.

Upvotes: 0

Related Questions