c# - App fails to find unmanaged dll when deployed -


i running web api asp.net 4.6 app running in cpu mode (though i've tried specifying x64) , makes call unmanaged x64 c dll. works fine when running within visual studio (using default iis express settings) though windows error 126 (the specified module not found.) when deploy server , run in iis or iis express though sure path dll correct. there else can try?

my native methods wrapper:

public static class nativemethods {     [dllimport("kernel32.dll", charset = charset.ansi, setlasterror = true)]     public static extern intptr loadlibrary(string dlltoload);      [dllimport("kernel32.dll", charset = charset.ansi, setlasterror = true)]     public static extern intptr getprocaddress(intptr hmodule, string procedurename);      [dllimport("kernel32.dll")]     public static extern bool freelibrary(intptr hmodule);      [dllimport("kernel32.dll", charset = charset.ansi)]     public static extern intptr getmodulehandle(string lpmodulename);      [dllimport("kernel32.dll")]     public static extern uint getlasterror(); } 

my load dll method:

private static void loaddll()     {         unloaddll(); //unload module first          if (string.isnullorempty(dlldirectory))             throw new applicationexception("dpi dll directory not specified.");          if (!file.exists(dllpath))             throw new applicationexception("could not find dpi dll.");          pdll = nativemethods.loadlibrary(dllpath);         //fails here         if (pdll == intptr.zero)             throw new applicationexception(string.format("failed load library <{0}> (errorcode: {1})", dllpath, marshal.getlastwin32error()));      } 

let me know if can make else more clear, thanks!

use dependency walker list of module's dependencies (module path dllpath). check need install visual c++ redistributable on server.

by ikenread: need check unmanaged dll compilation mode. if compiled in debug mode, dependent on debug versions of visual c++ redistributable dlls , absent (most likely) on production server.


Comments