SFML community forums

Bindings - other languages => DotNet => Topic started by: CssHammer on November 28, 2014, 07:08:04 pm

Title: "System.BadImageFormatException" in sfmlnet-graphics-2.dll
Post by: CssHammer on November 28, 2014, 07:08:04 pm
Exception happens when I compile my project. Image is too long >> ( http://cs621523.vk.me/v621523284/1ab1/9Gdogk6th1I.jpg ) (http://cs621523.vk.me/v621523284/1a9f/H5RtDqdIZSU.jpg)
sfml .dlls grabbed from lastest GitHub update, csfml .dlls taken from http://www.nightlybuilds.ch/files/download/161/CSFML-Visual%20Studio-2013-32.7z
Title: Re: "System.BadImageFormatException" in sfmlnet-graphics-2.dll
Post by: CssHammer on December 05, 2014, 05:17:25 pm
Can anyone help?
Title: Re: "System.BadImageFormatException" in sfmlnet-graphics-2.dll
Post by: Ztormi on December 05, 2014, 06:48:02 pm
Try changing project's target platform to x86/x64.
Title: Re: "System.BadImageFormatException" in sfmlnet-graphics-2.dll
Post by: CssHammer on December 06, 2014, 09:54:51 pm
It doesn`t help
Title: Re: "System.BadImageFormatException" in sfmlnet-graphics-2.dll
Post by: windsorperma on December 09, 2020, 08:07:34 am
The exception that is thrown when the file image of a dynamic link library (DLL) or an executable program is invalid. If you get a BadImageFormatException when interfacing with a native DLL, it almost always means that you are trying to interface with a 32-bit DLL while running in the 64-bit CLR, or vice versa. In most cases you might be  facing the problem with your website after deploying on server.

Make sure that you are not having 32-bit / 64-bit conflict. So, you need to adjust your application pool to Enable 32-Bit  or 64-Bit accordingly. Set the Target platform setting on your c# (http://net-informations.com/faq/default.htm) EXE project, not your class library project. Alternatively, you can ship both 32-bit and 64-bit DLLs with different file names, define separate P/Invoke stubs for each version, and decide which one to call at runtime. The easiest way to do this would probably be to wrap your native calls in an interface (e.g., INativeMethods) and choose which implementation to instantiate at runtime based on IntPtr.Size. With this method, you could still target AnyCPU.