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

makc
  • 2,569
  • 1
  • 18
  • 28
Seçkin Durgay
  • 2,758
  • 4
  • 27
  • 36
  • 2
    In your Winforms project: Project + Properties, Compile tab, change Platform target to x86. Or build a 64-bit version of the C++/CLI assembly. – Hans Passant Mar 09 '12 at 09:16

2 Answers2

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.

Seçkin Durgay
  • 2,758
  • 4
  • 27
  • 36
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.

Anzurio
  • 16,780
  • 3
  • 39
  • 49