Asp.Net C# DllImport problem

I want to import DLL file in my web site project. I have dll file "my.dll" in folder C:DLLDir and I'm using the code :

[DllImport("C:DLLDirmy.dll", EntryPoint = "Out32")]

This works ok. But I want to use relative path (web site root path) . I'm trying to put "my.dll" in "bin" or root folder and I'm using the code :

   [DllImport("my.dll", EntryPoint = "Out32")]

but I'm getting the error: Unable to load DLL 'my.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

Any ideas?


I think you may want to check out the following SO question first (since it's related to your case):

DllImport failed to locate DLL even though it is in the PATH

As other people has suggested, check the PATH environment variable to make sure that C:DLLDir is there. You can read more about how to do configure your environment variables here.

Check out this MSDN forum post as well (seems like there was an issue with dependencies).

If it's a COM DLL you're importing then it might also requires to be registered first on a target machine (although I'm not sure if this is needed). Read more here.


Either you did not copy my.dll to Bin folder where it should be loaded. Using Process Explorer ( http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx) will likley show where it tries to load this file from.

EDIT: thanks to volpav for reminding that it is unmanaged DLL - ignore manged portion... ...assembly have some other dependencies. Check out http://blogs.msdn.com/b/suzcook/archive/2003/05/29/57120.aspx that details investiagtion of such failures (search for "assembly load fussion log" for more links).


转到“ Properties/Build选项卡,然后将“平台目标”设置为x86

链接地址: http://www.djcxy.com/p/44444.html

上一篇: DLLImport无法加载DLL

下一篇: Asp.Net C#的DllImport问题