Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DLLImport在VS中工作,但在IIS中不工作_C#_Asp.net_Web Services_Iis_Dll - Fatal编程技术网

C# DLLImport在VS中工作,但在IIS中不工作

C# DLLImport在VS中工作,但在IIS中不工作,c#,asp.net,web-services,iis,dll,C#,Asp.net,Web Services,Iis,Dll,我们有一个使用第三方DLL的Soap Web服务项目。在VisualStudio中,当我运行程序时,它工作得非常好。它可以找到dll。但是当我将项目放入IIS时,webservice找不到dll。下面是DLLImport部分 [DllImport(@"/dll/y1d431_mit.dll", EntryPoint = "Y1DPackG", SetLastError = false, ExactSpelling = true)] private static exter

我们有一个使用第三方DLL的Soap Web服务项目。在VisualStudio中,当我运行程序时,它工作得非常好。它可以找到dll。但是当我将项目放入IIS时,webservice找不到dll。下面是DLLImport部分

[DllImport(@"/dll/y1d431_mit.dll",
        EntryPoint = "Y1DPackG", SetLastError = false, ExactSpelling = true)]
    private static extern void Y1DPackG(ref int ErrorNumb, ref int ErrorMsgs,
        string RegCustomer, int RegPassword, int CostOptim, int IgnoreLast,
        int EffortLev, int ReduceLays, int PrefShort, int DiffStocks,
        int DiffPieces, int ReusLength, int GapItIt, int GapItEnd,
        int GapGripEnd, int OptimTime, int IterMult, int LayByMark,
        int RunMsgMode, int ReservInp2, ref int StockGrLth, ref int StockGrCst,
        ref short StockGrQty, ref int PartGrLth, ref int PartGrMrkID, ref short PartGrQty,
        ref int Critsum, ref int Effsum, ref int StockSum, ref int PartSum,
        ref int LengthSum, ref int WasteSum, ref int CostSum, ref int LastStockNo,
        ref int LastParts, ref int LastLength, ref int LastWaste, ref int LastCost,
        ref int PatternSum, ref int LayoutSum, ref int LayoutCuts, ref int ReservOut1,
        ref int ReservOut2, ref short StockGrNo, ref short PartGrNo, ref short PartStockNo,
        ref short StockLayNo, ref short StockPatNo, ref short StockParts, ref int StockWaste);

IIS根据DLLImport语句在哪里查找dll文件?根据DLLIMPORT语句,我应该将dll文件放在哪里,以便IIS找到它?

加载Sysinternal的free。在运行执行dlliport的代码之前启动它,并在它出错后停止事件收集。这个工具将告诉你正在发生的每一件事,包括IIS从哪里开始搜索它。它还会告诉您是否有权限错误


如果它是64位系统上的32位dll,则可能出现权限错误,因为该dll随后将通过WOW64运行,并可能复制到WOW64目录中执行。默认情况下,这不是任何匿名internet用户帐户都可以访问的目录。

谢谢标记。Process Monitor向我显示了Windows查找DLLImport非托管/本机DLL及其所有依赖项/导入的确切位置。我找到了两种方法来找到我的DLL:

方法#1:SetDllDirectory()

方法#2:使用我的应用程序的DLL目录预挂起PATH环境变量:

using System.Web;

string dllDir = Path.Combine(HttpRuntime.AppDomainAppPath, @"myAppDLLDirectory\");
string currentPath = Environment.GetEnvironmentVariable("path");
Environment.SetEnvironmentVariable("path", $"{dllDir};{currentPath}");
此路径修改仅影响当前进程

p、 如果你的错误消息说它找不到你的DLL,但是你的DLL在DLL搜索路径上,这可能真的意味着你的DLL导入的DLL之一找不到。例如,我的DLL依赖于“vcruntime140d.DLL”和“ucrtbased.DLL”,这是我在开发机器上拥有的,但不在部署到的服务器上。使用“dumpbin.exe/imports my.dll”列出依赖项。Dumpbin可从Visual Studio“x64本机工具命令提示符”获得

using System.Web;

string dllDir = Path.Combine(HttpRuntime.AppDomainAppPath, @"myAppDLLDirectory\");
string currentPath = Environment.GetEnvironmentVariable("path");
Environment.SetEnvironmentVariable("path", $"{dllDir};{currentPath}");