BadImageFormatException, when trying to add .dll file to C# project - Intel realsense SDK


Every time i try to compile i'm getting this error:

System.BadImageFormatException: 'An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)'

when i try to run session = PXCMSession.CreateInstance();

I'm running Windows 10 pro, 32 bit operating system.

Added reference to file:

c:\Program Files\Intel\RSSDK\bin\win32\libpxcclr.cs.dll

added to post build evenent:

if "$(Platform)" == "x86" ( copy /y "$(RSSDK_DIR)\bin\win32\libpxccpp2c.dll" "$(TargetDir)" ) else ( copy /y "$(RSSDK_DIR)\bin\x64\libpxccpp2c.dll" "$(TargetDir)" )

And in build tab changed platform target from Any CPU to X86

asked on Stack Overflow Jun 12, 2017 by mowinka

2 Answers


That exception is usually, in my experience, due to a x64/x86 conflict. Are you definitely referencing the x86 version of libpxcclr.cs.dll?

answered on Stack Overflow Jun 12, 2017 by jb455

The fix is to go back to cmake and build with the x64 compilers on your system. If you don't see the prompt for the compiler version, delete the "build" directory and try cmake-gui again. All the C# examples work in x64 but don't in 32-bit.

answered on Stack Overflow Sep 25, 2018 by Bob Davies

User contributions licensed under CC BY-SA 3.0