简体   繁体   中英

Compress and Extract with SevenZipSharp

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM