C++/Cli : Could not load file or assembly X or one of its dependencies. is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)

8

I have a C++ project, a C++\Cli project and a c# win forms project.
When i access the cli project from win forms project, i can access and use cli project functions. But when i include my cpp project headers into cli project, i get this run time error from my c# project when i access the cli project.

  CliWrapper.Func meta = new CliWrapper.Func();

This is the error i have taken :

BadImageFormatException : Could not load file or assembly X or one of its dependencies. is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)

I realized that #include <boost/thread.hpp> causes the problem

boost
c++-cli
boost-thread
asked on Stack Overflow Mar 9, 2012 by Seçkin Durgay • edited Aug 15, 2013 by makc

2 Answers

5

I have found the solution :

http://marc.info/?l=boost-users&m=123425857320026

In Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions add BOOST_ALL_DYN_LINK in order to force the usage of the DLLs. In addition copy the necessary DLLs to the directory where the executable resides. E.g. copy boost_thread-vc90-mt-gd-1_XX.dll to MyApp/bin/Debug.

answered on Stack Overflow Mar 9, 2012 by Seçkin Durgay
3

It is very likely that your C++ project is compiled as Win32 and your C# project is either AnyCPU being ran on a 64-bit machine or, simply, an x64 assembly.

Configure your C# and C++/CLI project to target x86 architecture.

answered on Stack Overflow Mar 9, 2012 by Anzurio

User contributions licensed under CC BY-SA 3.0