Costura 未加载本机 Dll

约翰亨特

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

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

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

项目还是找不到文件,报错 Unable to load DLL

在 procmon 中查看时,我可以看到它在本地文件夹中查找文件,然后在 %temp%\costura\1D5629B8D94FC3E9B53C7AB358A0E123\native.dll 中查找,但找不到它。它似乎没有在“32”文件夹中寻找它。

我在配置文件 Unmanaged32Assemblies、PreloadOrder 中尝试了几个选项,但它们都有相同的结果。

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

米纳克希

在我的情况下,我尝试访问临时路径以使用以下代码设置库路径并且它起作用了。

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章