【问题标题】:Costura not loading Native DllCostura 未加载本机 Dll
【发布时间】:2019-05-01 17:43:01
【问题描述】:

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

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

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

项目仍然找不到文件,错误是无法加载DLL

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

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

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

【问题讨论】:

    标签: c# fody-costura


    【解决方案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; }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-20
      • 1970-01-01
      • 2020-07-19
      • 1970-01-01
      相关资源
      最近更新 更多