Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# / C++ in same solution - DllImport not finding DLL

I have a solution with a C++ dll project and a C# project that uses it. The problem is that the build path of the c++ project is in the solution folder and the c# is in the project's bin folder (each nested with debug/release), so the DllImport doesn't find them.
Is there a standard way to fix this?

like image 419
Baruch Avatar asked Nov 28 '11 16:11

Baruch


1 Answers

The way you are supposed to do this is to set the build path for both projects to the same 'bin' directory... preferrably one for the solution, not a project. Then just make all projects build to that one folder. You can change that from the Project settings.

Another technique is to use a post-build step for the C++ app that copies the DLL to the C# project's folder. That way you don't actually change any paths. You just copy over a DLL. Be careful here though because when you clean the C++ file's project, you may actually still have the copy in the C# projec'ts bin directory leaving you scratching your head as to why things aren't happening as expected.

Alternately, you can deploy the C++ DLL to a system path (also as part of a post-build step) but you'll have the same issues as stated above.

For debugging, I'd recommend these in the order presented.

like image 103
Mark A. Donohoe Avatar answered Oct 31 '22 16:10

Mark A. Donohoe