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 ?

Answers


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.


Need Your Help

Checking if an object exists after calling Activator.GetObject

c# .net .net-remoting

I'm developing a project with passive replication where servers exchange messages among themselves. The locations of each server are well-known by every other server.