Reputation: 916
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?
Upvotes: 3
Views: 14267
Reputation: 919
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
Upvotes: 1