globetrotter
globetrotter

Reputation: 1047

System.DllNotFoundException in .NET DLL

I took a program written in C/C++ and modified it's main function to accept some arguments as input and return a variable as output and created a Win32 DLL out of it. I then created a .NET DLL which uses InterOp to access the first DLL. Now when I load the .NET DLL in my C# app I get a System.DllNotFoundException from the DLL which is really baffling me as there were never memory issues with the program and both Win32/.NET dlls are located in the same directory (apart from modifying the main function, the code has not really changed). The solution was provided in this thread, which was my original question some time ago. I'm pretty sure that answer is correct but I'm just missing something.

You can download my VS solution Here. The solution contains three projects: the Win32 DLL, the .NET DLL, and a winform app that references the .NET DLL (but when trying to test gives the DLL exception). Any help or debugging guidance would be greatly appreciated.

Upvotes: 0

Views: 2959

Answers (1)

Prabhu Murthy
Prabhu Murthy

Reputation: 9261

Make sure you have placed the win32 dll on /windows/system32 folder(if only the dll name is passed to DllImport)

Alternatively you can also pass the full path of the dll to the DllImport Attribute.

Use a tool such as Dependency Walker to make sure you are not missing out on any dependent assembly.

Upvotes: 1

Related Questions