12

I am running a C# application that references a C++\CLI wrapper project which in turn references a native c++ project dependent on Boost 1.47 library (links to files of the form ...vc100-mt-gd-1_47.lib)

All libraries are statically linked and everything compiles great. Executing the C# app results in an exception: "...is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)." claiming some dependency is missing somewhere.

C# application is configured to x86 platform while all other projects are Win32, including boost's binaries.

EDIT: before adding the use of Boost library, it DID work

How can I track down the problem?

Leo
  • 1,213
  • 2
  • 13
  • 26
  • It is not a missing dependency kind of error. Has to be the platform target setting. – Hans Passant Nov 11 '11 at 13:08
  • eventhough it is stated as such in the error description? – Leo Nov 11 '11 at 13:30
  • 2
    Maybe AnyCPU is the proper setting, hard to guess from your description. Use SysInternals' ProcMon.exe tool to verify your assumptions. You'll see it loading any DLLs that you might not necessary assume to be a dependency for the native code. A 64-bit native DLL will trigger this exception when the platform target is x86. – Hans Passant Nov 11 '11 at 13:37
  • What details can I supply to help? Also, note the edit about boost being the cause – Leo Nov 11 '11 at 14:26
  • Which Boost libraries are you using? – ildjarn Nov 11 '11 at 17:48
  • Boost.Log and its dependencies. threading, date-time, file system.. – Leo Nov 11 '11 at 20:23
  • There is no official Boost.Log library, only proposed ones. Are you using John Torjo's proposed library or Andrey Semashev's or another? – ildjarn Nov 11 '11 at 20:55
  • The one that shows up on google first: Andrey Semashev. – Leo Nov 11 '11 at 21:25
  • I suspect that your issue may be specific to linking default-built Boost.Thread to an application using `/clr`. Have a look at [this thread](http://stackoverflow.com/q/5670248/636019) and its answer. – ildjarn Nov 15 '11 at 01:27
  • @leo did you get this problem solved? – Seth Feb 13 '12 at 02:10
  • 2
    @Seth, yes I have. I am not sure why this happens, but when a CLR project references a native project that uses boost, the boost libraries must be dynamically linked. static linkage fails for some reason. – Leo Mar 07 '12 at 09:26
  • All C++-CLI projects must be statically linkes to the CRT! And because your boost lib shares the CRT, they need to share the CRT, which means you have to use the DLL version of the CRT in all projects! – Jochen Kalmbach Jul 20 '13 at 20:13
  • As suggested before, there might be some missing dependencies. download dependency walker and examine the executable. Missing DLLs should be flagged as red – AcidJunkie Mar 10 '14 at 14:58

2 Answers2

1

It is known issue. The reason is Thread Local Storage (TLS) used in the Boost::Thread. To fix it you should either disable libboost_thread-vcXXX-mt-1_XX.lib and force linker to link your C++/CLI assembly with boost_thread-vcXXX-mt-1_XX.lib (stub of the boost_thread-vcXXX-mt-1_XX.dll).

Or you can create your own DLL and link it with libboost_thread-vcXXX-mt-1_XX.lib. Then you can link your C++ DLL with C++/CLI assembly.

See

Community
  • 1
  • 1
0

Came across this nasty error the other day whilst trying to get an IIS app running on my Visat 64bit PC:

Error: Is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)

Solution:

Within IIS 7 click on Application Pools (left hand side under {machine_name}) Select your app pool and then click Advanced Settings on the right. Second setting in the list: Enable 32-Bit Applications - must be set to True.