3

I'm trying to compress and extract files with SevenZipSharp, but I'm getting following error:

Can not load 7-zip library or internal COM error! Message: failed to load library.

My code:

string extractFrom = @"C:\Test\Test.7z";
string extractTo = @"C:\Test2";

string compressFrom = @"C:\Test2";
string compressTo = @"C:\Test\Test2.7z";

SevenZipBase.SetLibraryPath(@"C:\Program Files\7-Zip\7z.dll");

SevenZipCompressor compressor = new SevenZipCompressor();
compressor.CompressionMode = CompressionMode.Create;
compressor.TempFolderPath = Path.GetTempPath();
compressor.ArchiveFormat = OutArchiveFormat.SevenZip;
compressor.CompressDirectory(compressFrom, compressTo);//Error

SevenZipExtractor extractor = new SevenZipExtractor(extractFrom);
extractor.ExtractArchive(extractTo);//Error

The error is at:

compressor.CompressDirectory(compressFrom, compressTo);

and at:

extractor.ExtractArchive(extractTo);

How can I solve this problem?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
daniel59
  • 906
  • 2
  • 14
  • 31

1 Answers1

1

Most obvious answer: the dll is not at the given path.

But I assume you've tried that, but if you mix 32 bit and 64 bit applications this is also a known issue. So if your application is running 32 bits and the 7zip is installed as x64 this error will be thrown.

Also see this: A reference to .dll could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component

Community
  • 1
  • 1
Leon
  • 919
  • 6
  • 21
  • 1
    I tryed with 32-Bit and 64-Bit and both are not working. – daniel59 Oct 14 '15 at 08:55
  • SevenZipSharp is basically just a wrapper for the COM object - since that error is being thrown I suggest you read into the answer (and links) from the referenced SO question – Leon Oct 14 '15 at 08:57
  • 2
    I just found my mistake: I use .Net 4.5.2 but SevenZipSharp is just compatible up to .Net 4.0. – daniel59 Oct 14 '15 at 09:10
  • @daniel59: I use SevenZipSharp, too, but my project uses .Net 4.5.2, so it may have had some other reason in your case. – Tobias Knauss Nov 15 '18 at 13:52