tags:

views:

119

answers:

1

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 ?

Thanks.

+3  A: 

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.

Daniel Earwicker
DLL and C# project has been written in 32-bit enviroment
Mishgun_
And the host c# program is being built and run on a 32-bit OS?
Daniel Earwicker
no, it bult on w2k3 x64. Is that problem ?
Mishgun_
Yes, see update.
Daniel Earwicker
thanks.........
Mishgun_