Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 620
Seçkin Durgay Avatar asked Mar 09 '12 08:03

Seçkin Durgay


2 Answers

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.

like image 177
Seçkin Durgay Avatar answered Nov 07 '22 15:11

Seçkin Durgay


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.

like image 3
Anzurio Avatar answered Nov 07 '22 16:11

Anzurio