When calling C functions with InterOp Invoke, although the C DLL is already in the same folder as the target assembly, however, it is common to see the “DllNotFoundException” Exception. One of the most possible reason is that the C DLL depends on other legacy DLLs, and such dependents are not in the same directory as the assembly. For instance, for the below Motor.DLL, it depends on four DLLs:
Copy all the depended DLLs to the assembly output folder, and rebuild, all will be fine.
Posted in Dotnet/C#
