2016-07-21 11 views
0

Web API Asp.Net 4.6アプリを任意のCPUモードで実行していますが(これもx64を指定して試しましたが)、アンマネージx64 C dllを呼び出します。私はWindowsエラー126(指定されたモジュールが見つかりませんでした)が表示されますが、別のサーバーに展開し、IISまたはIIS Expressで実行しても、これは確かですが、Visual Studio(デフォルトのIIS Express設定を使用) DLLへのパスが正しいです。私が試すことができる何か他にありますか?デプロイ時にアプリケーションがアンマネージドdllを見つけることができない

私のネイティブメソッドラッパー:

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(); 
} 

マイロードDLL方法:

private static void LoadDll() 
    { 
     UnloadDLL(); //Unload the 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 to load library <{0}> (ErrorCode: {1})", DllPath, Marshal.GetLastWin32Error())); 
    } 

は、私は、何か他のものがより明確に感謝を作ることができるなら、私を知ってみましょう!

+0

[Dependency Walker](http://www.dependencywalker.com/)を使用して、モジュールの依存関係のリスト(パスDllPathを持つモジュール)を取得します。また、サーバーにVisual C++ Redistributableをインストールする必要があります。 –

+0

@ArtavazdBalayanありがとうございました!私は過去にDependency Walkerを使用しましたが、ここでそれを使うとは思わなかった。 DLLはデバッグモードでコンパイルされ、DLLのデバッグバージョンを探していましたが、これは明らかに本番サーバーにはありませんでした。あなたが答えとして再投稿したいのであれば、私はそれを喜んで受け入れます。再度、感謝します。 – ikenread

答えて

0

Dependency Walkerを使用して、モジュールの依存関係のリスト(パスDllPathを持つモジュール)を取得します。また、サーバーにVisual C++ Redistributableをインストールする必要があります。

ikenread:アンマネージドDLLコンパイルモードを確認する必要があります。デバッグモードでコンパイルされている場合、Visual C++再配布可能なDLLのデバッグバージョンに依存し、それらは実稼働サーバー上に存在しなくなります。

関連する問題