无法加载7-zip库或内部COM错误。库无效

时间:2017-11-06 16:38:46

标签: c# 7zip

以下是我正在使用的代码的示例,但我找不到问题的修复程序。使用C#我非常环保,但我已经为7Zip引用了库,尽管编译代码时出现以下错误。 Visual Studio中标记的行有注释。

  

错误消息:无法加载7-zip库或内部COM错误!   消息:库无效。

namespace SevenZipTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Compression for Multi-volumes has begun");

            string dll = @"C:\Project\VsProgram\libs\SevenZipSharp.dll";
            string source = @"SourceFilePath";
            string output = @"ZipFileOutputPath";

            SevenZipCompressor.SetLibraryPath(dll);
            SevenZipCompressor compressor = new SevenZipCompressor();
            compressor.ArchiveFormat = OutArchiveFormat.SevenZip;
            compressor.CompressionMode = CompressionMode.Create;
            compressor.TempFolderPath = System.IO.Path.GetTempPath();
            compressor.VolumeSize = 10000000;   // output file size in bytes
            compressor.CompressDirectory(source, output); //This line is where I am getting the flag in the code that gives me the listed error message.

            Console.ReadLine();
        }
    }
}

关于这一点需要注意的一点是我已经对它进行了一些研究,我也尝试了不同的代码结构方法,但我所看到的大部分内容都没有为我提供解决方案。这可能是一个重复的问题,但我还没有为我的目的找到一个来源。

我几乎可以通过Google阅读我能找到的所有帖子。

在代码中应用了修复程序,我已经能够运行该程序了,但我现在收到一个异常说:

  

"由于SevenZipSharp中的错误,执行失败。请   报告它   http://sevenzipsharp.codeplex.com/WorkItem/List.aspx,发布后发布   编号并附上档案。"

我现在想看看我能找到什么。

2 个答案:

答案 0 :(得分:3)

如果启动项目在其属性中设置为“首选32位”,则在指定64位7z.dll时可能会导致此错误。取消选中该属性可以为我解决此错误。

答案 1 :(得分:2)

SevenZipSharp需要一个7-zip 原生库才能运行。您必须在致电SetLibraryPath时指定7-zip dll(7z.dll,7za.dll等)的路径。

您正在做的是指定SevenZipSharp 程序集dll 的路径,这是没有意义的:它不是本机7zip库。获取7z.dll(例如来自here)并设置dll路径。

相关问题