Unmanaged DLLs fail to load on ASP.NET server Unmanaged DLLs fail to load on ASP.NET server asp.net asp.net

Unmanaged DLLs fail to load on ASP.NET server


This happens because the managed dlls get shadow copied to a temporary location under the .NET Framework directory. See http://msdn.microsoft.com/en-us/library/ms366723.aspx for details.

Unfortunately, the unmanaged dlls do NOT get copied and the ASP.NET process won't be able to find them when it needs to load them.

One easy solution is to put the unmanaged dlls in a directory that is in the system path (type "path" at the command line to see the path on your machine) so that they can be found by the ASP.NET process. The System32 directory is always in the path, so putting the unmanaged dlls there always works, but I would recommend adding some other folder to the path and then adding the dlls there to prevent polluting the System32 directory. One big drawback to this method is you have to rename the unmanaged dlls for every version of your application and you can quickly have your own dll hell.


As an alternate to putting the dll in a folder that is already in the path (like system32) you can change the path value in your process by using the following code

System.Environment.SetEnvironmentVariable("Path", searchPath + ";" + oldPath)

Then when LoadLibrary tries to find the unmanaged DLL it will also scan searchPath. This may be preferable to making a mess in System32 or other folders.


Try putting the dlls in the \System32\Inetsrv directory. This is the working directory for IIS on Windows Server.

If this doesn't work try putting the dlls in the System32 directory and the dependency files in the Inetsrv directory.