0

I've downloaded the latest compiled version of FreeImage, then build FreeImageNet wrapper. Put FreeImage.dll and FreeImageNet.dll on the same folder as my executable (the sample code). But everytime I run it, it says freeimage.dll is missing. I modified the code on FreeImageWrapper.cs and remove the exception handler

public static bool IsAvailable()
        {
            /*try
            {*/
                // Call a static fast executing function
                Version nativeVersion = new Version(GetVersion());
                Version wrapperVersion = GetWrapperVersion();
                // No exception thrown, the library seems to be present
                return
                    (nativeVersion.Major > wrapperVersion.Major) ||
                    ((nativeVersion.Major == wrapperVersion.Major) && (nativeVersion.Minor > wrapperVersion.Minor)) ||
                    ((nativeVersion.Major == wrapperVersion.Major) && (nativeVersion.Minor == wrapperVersion.Minor) && (nativeVersion.Build >= wrapperVersion.Build));
            }
            /*catch (DllNotFoundException)
            {
                return false;
            }
            catch (EntryPointNotFoundException)
            {
                return false;
            }
            catch (BadImageFormatException)
            {
                return false;
            }*/

        }

It always throws BadImageFormatException. It seems the problem is on the native dll (freeimage.dll) ?

How do I fix it ?

Thanks in advance.

I'm using Visual C# 2010 Express

Irwan
  • 783
  • 1
  • 13
  • 28

1 Answers1

2

This happens very often if you try to load a unmanaged 32bit dll into a 64bit process. To get around this problem open the properties of your startup project and change under Built - PlatformTarget the type from Any CPU to x86.

Oliver
  • 43,366
  • 8
  • 94
  • 151
  • ... or get the 64 bit version of the FreeImage dll. ;) – J. Steen Jul 11 '12 at 11:56
  • Thanks! I left option to any cpu on Windows 7 64 before – Irwan Jul 11 '12 at 12:08
  • I was trying to use the x64 dlls and had the same problem. But I discovered an option in the build configuration called "Prefer 32-bit" I unchecked that option and it worked perfectly afterwards. I was very glad I didn't to change from Any CPU. That would have been ugly. – Liz Sep 16 '20 at 20:34