using a C++ library from C# - load error

J

jmagaram

i've been tearing my hair out over this for hours. i can reference a C++
library from my C# code on my dev machine, but when i copy the entire Debug
directory to another computer my code fails, giving a "Could not load file or
assembly <nameofC++library>...the application configuration is incorrect."

To repro, I first create a C++ CLR class library and add one class with a
simple function "int GetAge()" that returns the number 20. I then create a
Windows app with a form and a button on it that calls GetAge() and displays
the result in a message box. To reference the C++ library, I click on
References, Add Reference, Projects, and then the name of my C++ class
library project. The code works fine - debug and release - on my dev machine.
I copy the Debug (or Release) directory to an XP machine and run it; the form
pops up but as soon as I click the button (which calls into the C++ library)
it croaks. This is VS 2005, .net 2.0.

What am I doing wrong? My scenario couldn't be a simpler example of C++ and
C# playing nice together.
 
J

jmagaram

i solved it by creating a setup program. you can't xcopy an app that uses a
managed C++ library. apparently additional DLLs are needed beyond the .net
framework and the DLLs produced by your app. you need msvcm80.dll and a few
other DLLs for this interop to work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top