Costura未加载本机DLL

3

我无法让Costura加载我的项目需要运行的本地dll。这是一个完整的本地dll,因此它不是项目中的引用。

我已将该dll添加到我的项目的costura32文件夹中,并将其设置为嵌入式资源。

当我运行项目时,我可以看到costura已将dll提取到%temp%\costura\1D5629B8D94FC3E9B53C7AB358A0E123\32\native.dll。

但项目仍然无法找到该文件,出现“无法加载DLL”的错误。

在查看procmon时,我发现它首先在本地文件夹中查找该文件,然后在%temp%\costura\1D5629B8D94FC3E9B53C7AB358A0E123\native.dll中查找,但未能找到它。它似乎没有在“32”文件夹中查找。

我已尝试在配置文件Unmanaged32Assemblies和PreloadOrder中使用几个选项,但结果都一样。

我看不出我在这里做错了什么。

1个回答

1
在我的情况下,我尝试使用以下代码访问临时路径以设置库路径,它起作用了。
   private bool SetupSevenZipLibrary()
    {
        string costuraExtractionPath = null;
        try
        {
           DirectoryInfo di = null;

            string costuraTempPath = Path.Combine(
                Path.GetTempPath(),
                "Costura" //ex: Costura
            );

            di = new DirectoryInfo(costuraTempPath);
            if (!di.Exists)
                return false;
            costuraExtractionPath = di.GetDirectories().First().FullName;
       
            if (!Directory.Exists(costuraExtractionPath))
                throw new Exception();

            string sevenZipPath = Path.Combine(
                costuraExtractionPath, 
                Environment.Is64BitProcess ? "64" : "32", "7z.dll"
            );
            if (!File.Exists(sevenZipPath))
                throw new Exception();

            SevenZipBase.SetLibraryPath(sevenZipPath);
            return true;
        }
        catch { return false; }
    }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接