开发者

Asp.Net C# DllImport problem

开发者 https://www.devze.com 2023-02-03 11:32 出处:网络
I want to import DLL file in my web site project. I have dll file \"my.dll\" in folder C:开发者_StackOverflow\\DLLDir and I\'m using the code :

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

[DllImport("C:\\DLLDir\\my.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).


Go to Properties/Build tab, and set Platform target to x86.


I believe the DLL has to be on your path (if not absolute). And what will likely surprize you is that CWD is not on your path unless you specifically add "." in your PATH variable.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号