简体   繁体   中英

C++/CLI DLL on C# doesn't compile

I wrote a wrapper DLL for some native c++ functions and compiled it in c++/CLI, then I added a reference to C# project, functions indicates there, but when I try compile project I get this error:

Additional information: Could not load file or assembly 'lib, Version=1.0.3742.39593, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.

What's the problem ?

64-bit vs 32-bit incompatibility is the most common cause of that error.

In the Project settings page of the C# project your Platform target will be set to Any CPU . This means that on a 64-bit system the program will run in a 64-bit process. It will then be unable to load DLLs that target 32-bit (native DLLs can't switch to suit the process.)

So you need to set it to x86. In VS2010 the default will be x86 for new projects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM