Title: Load unmanaged DLL on IIS
Tags: iis
Question: My managed application has a few dependencies on unmanaged DLLs. Even though my unmanaged DLLs are deployed in my bin folder they don’t get loaded. I already found a (hopefully) outdated SO post which points out two possible solutions:
add dlls to a well-known lookup path (e.g. \System32\Inetsrv)
add my bin folder to PATH
However, I don’t like either solution as it basically adds a dependency outside my deployment folder (=outside my jurisdiction). Can’t I let IIS know to load an unmanaged DLL (e.g. through web.config)?
Comment: @Dunken did you ever find a solution to this?

Comment: it will not help, but could you specify your version of IIS ?

Comment: Sure, I'm using IIS 7.5


Here is another answer: You could load the unmanaged DLL passing the full path where it's located to LoadLibraryEx:
[DllImport(&quot;kernel32.dll&quot;, SetLastError = true)]
public static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hReservedNull, LoadLibraryFlags dwFlags);
//get the physical path of the root directory of the application
string rootPath = System.Web.HttpContext.Current.Server.MapPath(&quot;~&quot;);
string libPath = Path.Combine(rootPath, &quot;bin&quot;, &quot;relative path to your DLL&quot;);
var h = LoadLibraryEx(libPath, IntPtr.Zero, NativeDlls.LoadLibraryFlags.LOAD_WITH_ALTERED_SEARCH_PATH);
if (h == IntPtr.Zero)
throw new Exception(&quot;Error in LoadLibrary: &quot; + Marshal.GetLastWin32Error());
Library should be set to be copied to the output directory of the build.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2014:00:02/10/14', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<iis>', 'Title': 'Load unmanaged DLL on IIS', 'ViewCount': 767, 'id': 21681004, 'user_AboutMe': '<h1>SOreadytohelp</h1>\n', 'user_AccountId': 246134.0, 'user_DisplayName': 'Dunken', 'user_Reputation': 8233.0, 'user_Views': 269.0, 'user_id': 520094.0}}