Free Support Forum -

PngDevice.Process causes MethodAccessException

I’m trying to turn a PDF page into a PNG image.

I’m using the code below:

            MemoryStream stream = new MemoryStream();
Document pdfDocument = new Document(sourceFileInfo.FullFilePath);
        <span style="color:#2b91af;">Resolution</span> resolution = <span style="color:blue;">new</span> <span style="color:#2b91af;">Resolution</span>(<span style="color:#2b91af;">ConfigSettings</span>.PreviewImageWidth, <span style="color:#2b91af;">ConfigSettings</span>.PreviewImagesHeight);
        <span style="color:#2b91af;">PngDevice</span> pngDevice = <span style="color:blue;">new</span> <span style="color:#2b91af;">PngDevice</span>(resolution);

        <span style="color:blue;">try</span>
            pngDevice.Process(pdfDocument.Pages.Cast<<span style="color:#2b91af;">Page</span>>().First(), stream);
        <span style="color:blue;">catch</span> (<span style="color:#2b91af;">Exception</span> ex)
            System.Diagnostics.<span style="color:#2b91af;">Debug</span>.Write(ex.ToString());

I get a MethodAccessException on pngDevice.Process with details:
Attempt by security transparent method ’ . .  (System.Drawing.Bitmap, System.Drawing.RectangleF)’ to access security critical method ‘System.Runtime.InteropServices.Marshal.Copy(IntPtr, Byte[], Int32, Int32)’ failed.
Assembly ‘Aspose.Pdf, Version=, Culture=neutral, PublicKeyToken=47b2d0fcacdd3eb6’ is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model.  Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception.
I’m running on ASP.NET 4.0 on IIS 7 on Windows 7.

Hi Muppets,

Thanks for using our products.

Can you please share the source PDF document so that we can test the scenario at our end. We are sorry for your inconvenience.

I have attached the PDF that is causing the issue. I have tried a few PDFs and some of them work.

This could be relating to issue Master slide images not appearing that I raised on the ASPOSE Slides forum. As this PDF was generated from a PPTX.

After some testing it seems any PDFs generated from PPTX has this issue. PPT generated PDFs however seem fine.

Hi Muppets,

Thanks for sharing the resource file.

I have tested the scenario while using Aspose.Pdf for .NET 6.3.0 and I am unable to notice any problem. The PDF document is properly being converted into PNG format. Can you please try using the new release version and in case you still encounter any issue, please feel free to contact.

For your reference, I have also attached the resultant PNG image that I have generated. Please take a look.