This project has moved. For the latest updates, please go here.

Read Pdf image using Magick.NET-x86.dll, StackOverflow exception?

Feb 6, 2014 at 1:04 PM
Edited Feb 6, 2014 at 1:08 PM
I am new to Magick.net. I found it last week.
What I am trying to do is reading a image of a pdf file.

Here is my code:
  public static System.Drawing.Bitmap GetPreview(string fn)
    {
        System.Drawing.Bitmap bmp;


        MagickReadSettings settings = new MagickReadSettings();
        settings.Density = new MagickGeometry(100, 100);
        settings.ColorSpace = ColorSpace.sRGB;
        settings.Format = MagickFormat.Jpeg;

       using (MagickImage coverPage = new MagickImage())
        {
           coverPage.Format = MagickFormat.Jpeg;

            coverPage.Quality = 50;
            coverPage.Read(fn+"[0]", settings);

           using (MemoryStream m = new MemoryStream())
            {
                 bmp = coverPage.ToBitmap(System.Drawing.Imaging.ImageFormat.Jpeg);
           }
     }

        return bmp;
    }
This code is ok for Magick.NET-x64.dll. But somehow if I set my platform to x86 and using Magick.NET-x86.dll, I got System.StackOverflowException when it executes
coverPage.Read(fn+"[0]", settings);

Any idea?

Thank you
Coordinator
Feb 6, 2014 at 1:49 PM
Edited Feb 6, 2014 at 6:06 PM
Are you using Q8 or Q16, .NET 2.0 or 4.0? And are you using the latest version of Magick.NET? Can you post a stacktrace?

Can you try if settings.FrameIndex=0 works?
Feb 7, 2014 at 7:05 PM
I am using .Net 4.0. I have tried both Q8 and Q16, same problem.

The dll I tried are
Magick.NET-6.8.8.201-Q16-x86-net40-client.zip
Magick.NET-6.8.8.501-Q8-x86-net40-client.zip

settings.FrameIndex=0 does not help.

There is no too much call stack. Here is message from visual studio.
An unhandled exception of type 'System.StackOverflowException' occurred in Magick.NET-x86.dll

By the way I am using visual studio 2012 professional.


Thank you
Coordinator
Feb 8, 2014 at 6:45 AM
Edited Feb 8, 2014 at 11:01 AM
Does the StackOverflowException only occur for a specific PDF file? Can you add a link to the PDF file if it does? Can you send me a detailed debug log? https://magick.codeplex.com/wikipage?title=Detailed%20debug%20information&referringTitle=Documentation

Did you also change the line 'coverPage.Read(fn+"[0]", settings);' to 'coverPage.Read(fn, settings);' when using settings.FrameIndex=0?
Feb 10, 2014 at 7:37 PM
Edited Feb 10, 2014 at 7:39 PM
StackOverflowException happens on every pdf I tried to open, not specific one.
I tried with 'coverPage.Read(fn, settings);'. It was same.

The debug log is:
MyTrace Information: 1 : 02/10/2014 15:27:48, 2014-02-10T15:27:48-05:00 0:00.016 0.016u 6.8.8 Policy Magick[6964]: policy.c/IsRightsAuthorized/485/Policy
Domain: Path; rights=Read; pattern="C:\Temp\09004006-00.PDF" ...
MyTrace Information: 1 : 02/10/2014 15:27:48, 2014-02-10T15:27:48-05:00 0:00.078 0.016u 6.8.8 Blob Magick[6964]: blob.c/OpenBlob/2535/Blob
read 3 magic header bytes
MyTrace Information: 1 : 02/10/2014 15:27:48, 2014-02-10T15:27:48-05:00 0:00.094 0.031u 6.8.8 Cache Magick[6964]: cache.c/DestroyPixelCache/960/Cache
destroy
MyTrace Information: 1 : 02/10/2014 15:27:48, 2014-02-10T15:27:48-05:00 0:00.094 0.031u 6.8.8 Configure Magick[6964]: configure.c/GetConfigureOptions/589/Configure
Searching for configure file: "magic.xml"
MyTrace Information: 1 : 02/10/2014 15:27:48, 2014-02-10T15:27:48-05:00 0:00.094 0.031u 6.8.8 Configure Magick[6964]: configure.c/GetConfigureOptions/589/Configure
Searching for configure file: "C:\Users\Sally.magick\magic.xml"
MyTrace Information: 1 : 02/10/2014 15:27:48, 2014-02-10T15:27:48-05:00 0:00.094 0.031u 6.8.8 Configure Magick[6964]: magic.c/LoadMagicList/682/Configure
Loading magic configure file "magic.xml" ...
MyTrace Information: 1 : 02/10/2014 15:27:48, 2014-02-10T15:27:48-05:00 0:00.094 0.031u 6.8.8 Policy Magick[6964]: policy.c/IsRightsAuthorized/485/Policy
Domain: Coder; rights=Read; pattern="PDF" ...
MyTrace Information: 1 : 02/10/2014 15:27:48, 2014-02-10T15:27:48-05:00 0:00.094 0.031u 6.8.8 Policy Magick[6964]: policy.c/IsRightsAuthorized/485/Policy
Domain: Path; rights=Read; pattern="C:\Temp\09004006-00.PDF" ...
MyTrace Information: 1 : 02/10/2014 15:27:48, 2014-02-10T15:27:48-05:00 0:00.094 0.031u 6.8.8 Blob Magick[6964]: blob.c/OpenBlob/2535/Blob
read 3 magic header bytes
MyTrace Information: 1 : 02/10/2014 15:27:48, 2014-02-10T15:27:48-05:00 0:00.094 0.031u 6.8.8 Cache Magick[6964]: cache.c/DestroyPixelCache/960/Cache
destroy
MyTrace Information: 1 : 02/10/2014 15:27:48, 2014-02-10T15:27:48-05:00 0:00.094 0.031u 6.8.8 Policy Magick[6964]: policy.c/IsRightsAuthorized/485/Policy
Domain: Path; rights=Read; pattern="C:\Temp\09004006-00.PDF" ...
MyTrace Information: 1 : 02/10/2014 15:27:48, 2014-02-10T15:27:48-05:00 0:00.094 0.031u 6.8.8 Blob Magick[6964]: blob.c/OpenBlob/2535/Blob
read 3 magic header bytes
MyTrace Information: 1 : 02/10/2014 15:27:48, 2014-02-10T15:27:48-05:00 0:00.109 0.047u 6.8.8 Configure Magick[6964]: configure.c/GetConfigureOptions/589/Configure
Searching for configure file: "delegates.xml"
MyTrace Information: 1 : 02/10/2014 15:27:48, 2014-02-10T15:27:48-05:00 0:00.109 0.047u 6.8.8 Configure Magick[6964]: configure.c/GetConfigureOptions/589/Configure
Searching for configure file: "C:\Users\Sally.magick\delegates.xml"
MyTrace Information: 1 : 02/10/2014 15:27:48, 2014-02-10T15:27:48-05:00 0:00.109 0.047u 6.8.8 Configure Magick[6964]: delegate.c/LoadDelegateList/1228/Configure
Loading delegate configuration file "delegates.xml" ...
MyTrace Information: 1 : 02/10/2014 15:27:48, 2014-02-10T15:27:48-05:00 0:00.109 0.047u 6.8.8 Configure Magick[6964]: nt-base.c/NTLocateGhostscript/1035/Configure
Ghostscript (GPL Ghostscript) version 8.15
MyTrace Information: 1 : 02/10/2014 15:27:48, 2014-02-10T15:27:48-05:00 0:00.109 0.047u 6.8.8 Configure Magick[6964]: nt-base.c/NTGhostscriptGetString/1101/Configure
registry: "HKEY_LOCAL_MACHINE\SOFTWARE\GPL Ghostscript\8.15\GS_DLL"="C:\Program Files (x86)\GPLGS\gsdll32.dll"
MyTrace Information: 1 : 02/10/2014 15:27:48, 2014-02-10T15:27:48-05:00 0:00.109 0.047u 6.8.8 Configure Magick[6964]: nt-base.c/NTGhostscriptGetString/1101/Configure
registry: "HKEY_LOCAL_MACHINE\SOFTWARE\GPL Ghostscript\8.15\GS_DLL"="C:\Program Files (x86)\GPLGS\gsdll32.dll"
Coordinator
Feb 10, 2014 at 7:47 PM
Can you upgrade Ghostscript to the latest version? The version you are using is from 2004.
Feb 11, 2014 at 2:28 PM
I did not know Magick.net needs Ghostscript. This explains why my code works for x64, not x86.
I have Ghostscript x64 installed long time ago, but not x86 Ghostscript on my computer.
My code works fine after I install Ghostscript x86.

Thank you
Apr 1, 2015 at 10:32 AM
I am also getting the error "An unhandled exception of type 'System.StackOverflowException' occurred in Magick.NET-x86.dll", I am using Visual Studio 2010, my C# MVC project platform target is x86 and successfully builds.
using (var images = new MagickImageCollection())
{
var pdfSettings = new MagickReadSettings { FrameIndex = 0, FrameCount = 1 };
images.Read(file, pdfSettings);
}
I have GhostScript (gs916w32.exe), Magick.NET-7.0.0.0011-Q16-x86-net40-client and Visual C++ Redistributable for Visual Studio 2012 Update 4 (vcredist_x86) installed but still this issuer persists when trying to read a pdf file.

I have tried multiple pdf files and even created a few from scratch to ensure no possible file corruption.

Can someone please advise as how to resolve this issue?
Coordinator
Apr 2, 2015 at 4:37 PM
Are you able to create a crashdump? This could help me track down the problem.
Coordinator
Apr 10, 2015 at 6:52 PM
Are you still experiencing this issue? I could really use the crash dump to figure out what is going on.
Apr 10, 2015 at 6:54 PM
May be I can help to find the cause.
These assemblies have the error mentioned above:
Magick.NET-7.0.0.0010-Q8-x86-net40-client
Magick.NET-7.0.0.0011-Q8-x86-net40-client
The most recent dll's version that converts pdf correctly is 7.0.0.0009.
Here is debug log from 7.0.0.0010: https://yadi.sk/i/Osu9m3qjfuZW2
Sorry, I wasn't able to post log here because of message size limit.
The code was:
using (var imageList = new MagickImageCollection())
{
  imageList.Read(sourcePath);
  int count = 0;
  foreach (MagickImage im in imageList)
  {
    im.Format = MagickFormat.Jpg;
    im.Quality = 70;
    im.CompressionMethod = CompressionMethod.LosslessJPEG;
    im.Write(string.Format("{0}-{1:000}.jpg", targetPath, count));
    count++;
  }
}
Thanks!
Coordinator
Apr 10, 2015 at 7:17 PM
Your logging looks incomplete did you remove some things from it? And are you able to provide me with a crash dump?
Apr 10, 2015 at 7:29 PM
No, I didn't remove anything from log; I've created new empty file right before running application and took it after the application have crashed with error.
Here is the dump without heap: https://yadi.sk/d/twUEb8qxfubcv
Coordinator
Apr 10, 2015 at 7:41 PM
Can you create one with the heap information? It is not telling me that much right now.
Apr 10, 2015 at 7:56 PM
Over 400 MB in my environment, are you sure?
Well, I put it in a zip: https://yadi.sk/d/p_XlTvjKfuczy
Have to go now, will be online tomorrow.
Coordinator
Apr 10, 2015 at 8:00 PM
I noticed you are using Magick.NET-7.0.0.0010. Can you try Magick.NET-7.0.0.0011? I did fix something in Magick.NET-7.0.0.0010 that caused a stack overflow exception.
Apr 10, 2015 at 8:18 PM
As I already mentioned, Magick.NET-7.0.0.0011 crashes with the same error while converting pdf.
Here are the log information plus dumps with and without heap for v7.0.0.0011 in the single archive: https://yadi.sk/d/NwooPAbDfudkg
Coordinator
Apr 11, 2015 at 1:42 PM
I just wanted to make sure it was still happening in version 7.0.0.0011. I contacted you through CodePlex to continue the conversation by e-mail.
Apr 11, 2015 at 6:07 PM
Replied the same way, sorry for the delay.
Coordinator
Apr 11, 2015 at 8:47 PM
I replied to the messages from CodePlex, you should have an e-mail from me in your gmail account. Once more, thank you for helping me figure out what is going on.
Coordinator
Apr 12, 2015 at 12:20 PM
With the help of kirbam I was able to find the bug that was introduced in Magick.NET 7.0.0.0010. I will publish a new release very soon to fix this problem.
Apr 13, 2015 at 7:41 AM
Thank you for getting back to me, however I was pressed for time to find a resolution, so had to use a different library.