7

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:\\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?

7
  • 1
    I think it want the absolute path to the dll. Server.MapPath should do the trick for you Commented Jan 9, 2011 at 2:18
  • Server.MapPath gives you the paths relative to you web directory location. So if you have the absolute path already it won't make any difference. Commented Jan 9, 2011 at 2:26
  • 1
    But Server.MapPath will allow the OP to use a relative path to the DLL, but pass in an absolute path to DLLImport. Commented Jan 9, 2011 at 2:34
  • eggheadcafe.com/software/aspnet/33238643/… You can put your DLL to system32 or you fix your path variable Commented Jan 9, 2011 at 2:45
  • 1
    Does my.dll have any dependencies? If so have you copied those dependencies to the websites bin directory also? Commented Jan 9, 2011 at 3:03

4 Answers 4

3

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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).

1 Comment

I believe it has nothing to do with Fusion since it's unmanaged DLL.
2

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.