Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Attempted to read or write protected memory. This is often an indication that other memory is corrupt. #80

Open
fscopel opened this issue Feb 26, 2015 · 4 comments

Comments

@fscopel
Copy link

fscopel commented Feb 26, 2015

I get this random error, any ideas where to start?

Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

StackTrace:
at Pechkin.PechkinBindings.wkhtmltopdf_convert(IntPtr converter)
at Pechkin.PechkinStatic.PerformConversion(IntPtr converter)
at Pechkin.SimplePechkin.Convert(ObjectConfig doc, Byte[] html)
at Pechkin.SimplePechkin.Convert(ObjectConfig doc, String html)
at Pechkin.Synchronized.SynchronizedPechkin.b__2(IPechkin conv, ObjectConfig obj, String txt)

@brendan-rice
Copy link

Aye you sure it is random? I was getting the same error. The first time a PDF was generated it would work fine, anytime after that I got the error above. It was in a web project and due to bad configuration as far as I could tell. Here is what I have for IIS that works fine:

    private byte[] GetPdfBytes(Quote quote, GetQuoteOutput quoteOutput, Tenant tenant)
    {
        string partialView = string.Format("PDF/Tennants/{0}/Template{1}", this.CurrentSession.TenantId,
            quote.TemplateId);

        string htmlText = RenderPartialViewToString(this, partialView, quoteOutput.Quote);

        string baseUrl = Request.Url.GetLeftPart(UriPartial.Authority);
        string headerUrl = string.Format(baseUrl + "/tenantfiles/{0}/header.html", tenant.TenancyName);
        string footerUrl = string.Format(baseUrl + "/tenantfiles/{0}/footer.html", tenant.TenancyName);

        //IPechkin pechkin = Factory.Create();

        var document = new HtmlToPdfDocument
        {
            GlobalSettings =
            {
                ProduceOutline = true,


                DocumentTitle = "Quote - " + quoteOutput.Quote.Reference,
                Margins =
                {
                    Top = 3,
                    Right = 1,
                    Left = 1,
                    Bottom = 3.4,
                    Unit = Unit.Centimeters
                }
            },
            Objects =
            {
                new ObjectSettings
                {
                    HtmlText = htmlText,
                    HeaderSettings = new HeaderSettings() {HtmlUrl = headerUrl, ContentSpacing = 6},
                    FooterSettings =
                        new FooterSettings
                        {
                            HtmlUrl = footerUrl,
                            RightText = "[page]/[toPage]",
                            FontSize = 9,
                            FontName = "Trebuchet MS",
                            ContentSpacing = 10
                        }
                }
            }
        };

        // Keep the converter somewhere static, or as a singleton instance!
        // Do NOT run the above code more than once in the application lifecycle!

        byte[] pdfBytes = HtmlToPdfConverter.Converter.Convert(document);

        return pdfBytes;
    }

}

@sanore
Copy link

sanore commented Feb 19, 2016

I had the same problem and the static trick isn't working for me.

2016-02-19 17_26_25-2016-02-19 16_33_03-view detail png - windows photo viewer

@miyagisan221b
Copy link

3 years old, but still... did you end up working this one out?

@campbellja
Copy link

Please assist as we are also interested in a solution for this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants