質問

Azure Storageキューを使用してメッセージをWebJobに送信します。その後、このWebJOBはPDFを作成し、それをBLOBコンテナに格納します。これは私のDev-Machineでうまく機能します。メッセージが受信され、インスタンス化されたオブジェクトとPDFが作成され、BLOBストレージに格納されます。webjobをazureに展開すると、メッセージを受信した瞬間にメモリ不足例外が発生します。

記憶限度とは何ですか?

 public static void HandleNewRegistration(
        [QueueInput("pdf")] Models.Registration registration,
        [BlobOutput("pdf/{Name}.txt")] TextWriter writer,
        [BlobOutput("pdf/{Name}.pdf")] Stream pdfWriter)
    {
        try
        {
            // Store received registration in database (using EF)
            AppContext db = new AppContext();
            db.Registrations.Add(registration);
            db.SaveChanges();

            // Create PDF document (nothing fancy, just a section with a paragraph)
            var pdf = CreatePdf(registration);
            var renderer = new MigraDoc.Rendering.PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
            renderer.Document = pdf;
            renderer.RenderDocument();
            renderer.Save(pdfWriter,true);

        }
        catch (Exception e)
        {
            writer.WriteLine(e.Message);
            writer.WriteLine(e.StackTrace);
        }
        writer.WriteLine(registration.Name);
    }
.

これを使用すると、スタックトレースを使用したBLOBストレージ内のテキストファイルのみが終了します。

Out of memory.
   at System.Drawing.Graphics.FromHwndInternal(IntPtr hwnd)
   at System.Drawing.Graphics.FromHwnd(IntPtr hwnd)
   at PdfSharp.Drawing.XGraphics..ctor(Graphics gfx, XSize size, XGraphicsUnit pageUnit, XPageDirection pageDirection)
   at MigraDoc.Rendering.DocumentRenderer.PrepareDocument()
   at MigraDoc.Rendering.PdfDocumentRenderer.PrepareDocumentRenderer(Boolean prepareCompletely)
   at MigraDoc.Rendering.PdfDocumentRenderer.PrepareRenderPages()
   at MigraDoc.Rendering.PdfDocumentRenderer.RenderDocument()
   at WebJob.Program.HandleNewRegistration(Registration registration, TextWriter writer, Stream pdfWriter) in d:\Source\Workspaces\[...]\WebJob\Program.cs:line 43
.

役に立ちましたか?

解決

明らかにあなたはMigradocのGDI +ビルドを使用しています - Azure ServerにGDI +があり、Graphics.FromHwnd()は失敗します。

MigradocのWPFビルドを使用し、物事はAzureサーバーで問題を解決する必要があります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top