P/Invoke “DllNotFoundException” Exception

20 Nov

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.

Leave a comment

Posted by on November 20, 2009 in Dotnet/C#


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: