MagickImage ctor error for the only one tif file

Apr 29, 2015 at 12:22 PM
Edited Apr 29, 2015 at 12:26 PM
Hello everyone, I'm using Magick.Net in my project for a couple of months and everything worked perfect until I got an error while trying to create a MagickImage for a specific tif file. It works fine for all another tif files I'm trying to process. The error occurs in the following line:
using (var image = new MagickImage(fullFileName))
and looks like
An error occured while attempting to extract ...
Details: w3wp.exe: TIFF directory is missing required "ImageLength" field. `MissingRequired' @ error/tiff.c/TIFFErrors/570
StackTrace: at ImageMagick.AssemblyHelper.CreateInstance(Type type, Type[] parameterTypes, Object[] arguments) at ImageMagick.MagickImage..ctor(String fileName)
at Utility.ImageUtils.TurnOffFileRotation(String fullFileName)
at ...
But this image does have an ImageLength field and I'm able to read it by tiff tag 257. The only difference between this specific tif and others in a row, is it size, it is more than 130Mb, as the others are ~30Mb.

Can anyone help me with this issue? Thanks in advance!
Apr 29, 2015 at 2:28 PM
Can you post a link to the file that is failing for you? You can contact me through Codeplex if you don't want to share the image publicly.
Apr 29, 2015 at 3:18 PM
I sent you a message through Codeplex with the link to this naughty tif file. Thank you for your time!
Apr 29, 2015 at 6:46 PM
Edited Apr 29, 2015 at 10:23 PM
The problem with this file is that only first frame is correct. It will convert the image if you only read the first frame and since you are using MagickImage to read the file this is probably what you want. It is now making me think that this should be something that I could possibly automate. For now you will have to do this:
using (var image = new MagickImage(fullFileName + "[0]"))

// or

using (var image = new MagickImage(fullFileName, new MagickReadSettings()
        FrameCount = 1
EDIT: I just committed a patch to the git repository that makes sure that only one frame is read when you use the MagickImage class. This image can be read without any issues in the next release of Magick.NET that will be released later this week.
Apr 30, 2015 at 12:12 PM
Thank you very much, the code works perfect after applying changes you suggested.