Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

ASP.NET Web Api fails DllImport (LoadLibrary) on IIS

$
0
0

Hi, 
I'm developping a Web API that needs to call an unmanaged DLL written in C++.

Like here: http://blogs.msdn.com/b/eldar/archive/2006/09/22/how-to-call-c-dll-from-asp-net-c-code.aspx

In debugging (IIS Express), I'm able to call the function within the DLL and LoadLibrary is loaded correctly with a Handle.
Problem comes when I deploy my Web Api to my local machine (IIS 8): It recognizes the path of the DLL, permissions are also set properly, but LoadLibrary fails bacause I get a IntPtr.Zero.

I used Marshal.GetLastWin32Error() to detect the error, but I get error Code 193, which seems to have nothing to do with LoadLibrary.


Here's my code:

if (!Directory.Exists(PATH) && !File.Exists(PATH_DLL))
throw new Exception(string.Format("Dll not found: {0}.", PATH_DLL));

//LoadLibrary
hModule = DllInterop.LoadLibrary(PATH_DLL);
IsLoaded = (hModule != IntPtr.Zero);
if (!IsLoaded)
{
int errno = Marshal.GetLastWin32Error();
throw new Exception(string.Format("Failed to load library. Fehler:{0}.", errno));
}


I would be very grateful for your help. Thanks in advance!


Viewing all articles
Browse latest Browse all 1710

Trending Articles