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)"
Translated:
"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: http://www.sambeauvois.be/blog/2010/05/freeimage-and-x64-projects-yes-you-can/
...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: http://downloads.sourceforge.net/freeimage/FreeImage3154.zip
I need the dll converted to work with anycpu targeting, or a other solution to make it work, I'm working with VBNET.
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
):
"FreeImage DLL" [WIN32/WIN64]
archive from http://freeimage.sourceforge.net/download.html. 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 FreeImage3180Win32Win64.zip
.FreeImage\Wrapper\FreeImage.NET\cs\FreeImage.NET.sln
in VS; let it convert project format to 2019.UnitTest project
(to avoid errors due to missing NUnit package)."x64"
."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".Build
.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.FreeImage\Dist\x64\FreeImage.dll
.Optionally, verify that you can build and run Sample 1 in that .sln:
Debug + x64
; startup project Sample 1
.FreeImage.dll
.bin
folder now contains Sample01.exe
. That should also contain a copy of the FreeImageNet.dll
you previously built.FreeImage\Dist\x64\FreeImage.dll
into the folder where you found Sample01.exe
.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:
Debug + x64
.FreeImage.dll
, FreeImageNET.dll
, and FreeImageNET.pdb
into that folder that contains your .exe
.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.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.
You need to compile the freeimage library AND the .NET-wrapper to 64 bit.
http://www.sambeauvois.be/blog/2010/05/freeimage-and-x64-projects-yes-you-can/
User contributions licensed under CC BY-SA 3.0