How to use FreeImage.NET in a x64 targeting project (AnyCpu)?


I'm trying to use the FreeImage .NET wrapper in my project, my ptoject targets AnyCPU and the dll wrapper will not work under this, it will only works if I target x86 machine.

When I try to load a file using the wrapper targeting AnyCPU or X64 it throws this exception:

"Se ha intentado cargar un programa con un formato incorrecto. (Excepción de HRESULT: 0x8007000B)" 

"Intent to load a program with incorrect format (Excepción de HRESULT: 0x8007000B)"

I've tried to follow the steps to work with x64 freeimage in a net project:

...But my VS2012 can't open any of the solutions, it says "can't find localized resources".

The source of freeimage and the wrapper is here:

I need the dll converted to work with anycpu targeting, or a other solution to make it work, I'm working with VBNET.

asked on Stack Overflow Jul 19, 2013 by ElektroStudios • edited Jul 19, 2013 by ElektroStudios

2 Answers


Simplest solution is to use FreeImageNET nuget package. Caveat: I haven't tested this; I don't know how it deals with 32-bit vs 64-bit.

You can do so in your Solution Explorer - "Manage NuGet packages for Solution...".

Below instructions are for those who wish to build the .NET wrapper themselves.

To clarify Bernhard's answer:

To use FreeImage in a 64-bit project, it isn't enough to compile the ".NET-wrapper" FreeImageNet.dll as 64-bit.
Must also make sure that you are using 64-bit version of FreeImage.dll, FreeImage\Dist\x64\FreeImage.dll.

Note that this is not an "Any CPU" solution. Set your main exe's project Platform to "x64".

To build FreeImageNet.dll in 64-bit (tested in VS 2019 Community):

  • Download latest "FreeImage DLL" [WIN32/WIN64] archive from You DON'T need the "Source distribution", unless you want to build the underlying C++ dll. As I write this, the file you download is
  • Open FreeImage\Wrapper\FreeImage.NET\cs\FreeImage.NET.sln in VS; let it convert project format to 2019.
  • Unload UnitTest project (to avoid errors due to missing NUnit package).
  • Set Build Configuration / Platform to "x64".
  • Open Library / Properties / Build - Set "Treat warnings as errors" to "None". NOTE: This must be set for each "Platform" you build. So if you forgot to set Build Platform first, after setting Build Platform to x64, verify that this is still "None".
  • Rt-click Library project / Build.
  • Do for both Debug and Release build configurations, if you want to use Debug version with its FreeImageNET.pdb for symbols while debugging your app. You'll want the Release dll for the Release build of your app.
  • Any .exe that references this Library, must also reference FreeImage\Dist\x64\FreeImage.dll.

Optionally, verify that you can build and run Sample 1 in that .sln:

  • Set config to Debug + x64; startup project Sample 1.
  • Build. If you run now, it won't find FreeImage.dll.
  • Find what bin folder now contains Sample01.exe. That should also contain a copy of the FreeImageNet.dll you previously built.
  • You need x64 version of the underlying C++ dll. Copy FreeImage\Dist\x64\FreeImage.dll into the folder where you found Sample01.exe.
  • Set breakpoint at start of Sample's Program / Main method. Step through, look for any error messages in console window. Most importantly, make sure FreeImage.IsAvailable() check succeeds - doesn't say "FreeImage.dll seems to be missing".

Now you are ready to repeat this, with your own app:

  • Set your main exe project's config to Debug + x64.
  • Build. To make sure you know which bin folder you are building into.
  • Copy FreeImage.dll, FreeImageNET.dll, and FreeImageNET.pdb into that folder that contains your .exe.
  • [OPTIONAL] Add FreeImage\Wrapper\FreeImage.NET\cs\Library\Library.csproj to your solution. This is the "2019 format" version that VS 2019 created for you earlier. This makes it easy to debug into the wrapper sources.
  • NOW reference the two dlls in your exe project, and debug your project as usual. (Or reference the Library project as a dependency, plus FreeImage.dll.)

NOTE: Copying those files directly into your bin folder is the "dirty" way to do this. Was easiest way to verify you can build and run with the dlls. Much better is to have those dlls be part of your "sources" under source code control, copied to the bin folder as part of your build process. Google elsewhere for instructions on that.

answered on Stack Overflow Nov 22, 2019 by ToolmakerSteve • edited Nov 22, 2019 by ToolmakerSteve

You need to compile the freeimage library AND the .NET-wrapper to 64 bit.

answered on Stack Overflow Nov 22, 2013 by Bernhard

User contributions licensed under CC BY-SA 3.0