views:

74

answers:

1

I know you need to turn on the 'Native Code' debugger in order to step into the pinvoke'd dll, however I am not even getting to that point. Instead, when I try to step into the dll I am getting the following exception

"Unable to load DLL 'Native.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"

If I check my modules I see that the current .Net dll I am in is located in: C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\project\c4e2b8a9\1234a123\assembly\d12\de123456\12345678_0304cb01\dotnet.dll

So it makes sense that I am not finding my pinvoked dll, as it does not exist in this path. How can I make it so that when my code is run from the 'Temporary ASP.Net files' location, it will see my pinvoked dll? (Without hardcoding the path).

Current my decleration is as follows:

    [DllImport("Native.dll")]
    public static extern int RunTest();

Edit:

I found a similar question with some good suggestions. http://stackoverflow.com/questions/344608/unmanaged-dlls-fail-to-load-on-asp-net-server

A: 

In order for pinvoke to find the dll, the dll must be located in near .net dll or in one of the directories in the PATH variable. You can add the path of your application dynamically to the PATH env. variable of the process using Environment class. But you will still have to know the path to your application at the runtime.

Alex Reitbort